Solved

Vbs script or Batch file help

Posted on 2010-09-19
14
451 Views
Last Modified: 2012-05-10
Hi there,

I have 4 msi prerequisites that I need to install one after the other. I was thinking if I have them in a script will be helpful alonge with their silent command line switches.
The first program is VC++DISTRIBUTABLE.MSI /qn /norestart
the 2nd is SQLSERVER.MSI /QN /NORESTART
the 3rd is ramss11.msi /qn /norestart.
the 4th is iegs.msi /qn /norestart

Thanks
0
Comment
Question by:Zak
  • 5
  • 5
  • 4
14 Comments
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33713443
How about this as a bat file.

~bp
@echo off
start "" VC++DISTRIBUTABLE.MSI /qn /norestart
start "" SQLSERVER.MSI /QN /NORESTART
start "" ramss11.msi /qn /norestart.
start "" iegs.msi /qn /norestart

Open in new window

0
 
LVL 12

Expert Comment

by:Daz_1234
ID: 33714798
Hi smartmanwin,

The VBScript below should do exactly what you asked for.  It will display an error if any of the installs fail.

Regards,
Daz.


' Install Pre-Reqs





Dim arrCmd, wshShell, strProgDir, strCmd



'### Set the following line to the location of the msi files. Don't forget the trailing backslash

strProgDir = "g:\Program\Dir\"



arrCmd = Array("VC++DISTRIBUTABLE.MSI", _

               "SQLSERVER.MSI", _

               "ramss11.msi", _

               "iegs.msi")



For Each strCmd In arrCmd

    strCmd = "msiexec /i """ & strProgDir & strCmd & """ /qn /norestart"

    ret = wshShell.Run (strCmd, 1, True)

    CheckOk strCmd, ret

Next





Sub CheckOk(sCmd, iRet)

    If iRet <> 0 And iRet <> 3010 Then

        '# Error installing that component, return is not 0 or 3010 (reboot req).

        MsgBox "Error running command '" & sCmd & "'.  Return: " & iRet, vbCritical + vbSystemModal, "ERROR"

        WScript.Quit

    End If

End Sub

Open in new window

0
 

Author Comment

by:Zak
ID: 33722090
BillPrew,
On SMS when the package gets replicated to distribution points how does the batch file behaves?
Thanks,
0
 

Author Comment

by:Zak
ID: 33722119
In the end of the Program I want to COPY a 600MB folder by the name Tables to replace another Tables folder located in C:\Program files\Bentley\Tables
How can I add this command in the batch file.
Many thanks
0
 
LVL 12

Expert Comment

by:Daz_1234
ID: 33723423
Hi,

For the folder copy, I have added it to my VBScript below, which also has a couple of fixes for errors I missed in my original post.

Regards,
Daz.

P.S. just a little side advice:  If you are going to use a batch file, be careful about using the Start command as per Bill's first suggestion.  The reason is that Windows Installer can only install one MSI at a time, and if one is installing when another is called, the install will fail returning error code 1618 (Another installation is already in progress).  Just replace the Start "" part with msiexec /i and Bill's batch file will be fine.
' Install Pre-Reqs





Dim arrCmd, fso, wshShell, strProgDir, strCmd, ret

Dim strTablesSource, strTablesTarget



Set wshShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")



'### Set the following lines to the location of the msi files and Tables source folder. Don't add trailing backslashes

strProgDir = "g:\Program\Dir"

strTablesSource = "h:\source\folder\Tables"

strTablesTarget = "C:\Program files\Bentley\Tables"





arrCmd = Array("VC++DISTRIBUTABLE.MSI", _

               "SQLSERVER.MSI", _

               "ramss11.msi", _

               "iegs.msi")



For Each strCmd In arrCmd

    strCmd = "msiexec /i """ & strProgDir & "\" & strCmd & """ /qn /norestart"

    ret = wshShell.Run (strCmd, 1, True)

    CheckOk strCmd, ret

Next





CopyTablesFolder()



'# End Of Script



'________________________________________

'  Subroutines

'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯



Sub CheckOk(sCmd, iRet)

    If iRet <> 0 And iRet <> 3010 Then

        '# Error installing that component, return is not 0 or 3010 (reboot req).

        MsgBox "Error running command '" & sCmd & "'.  Return: " & iRet, vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

End Sub



Sub CopyTablesFolder()

    If Not fso.FolderExists(strTablesSource) Then

        MsgBox "Error: Source folder for Tables (" & strTablesSource & ") not found.", vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

    If fso.FolderExists(strTablesTarget) Then

        fso.DeleteFolder strTablesTarget, True

    End If

    If fso.FolderExists(strTablesTarget) Then

        MsgBox "Error: OLD target folder for Tables (" & strTablesTarget & ") not could not be deleted.", vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

    MakeDir strTablesTarget

    fso.CopyFolder strTablesSource, strTablesTarget

End Sub



Sub MakeDir(dir)

    If Not fso.FolderExists(dir) Then

        wshShell.Run "cmd /c MD """ & dir & """", 0, True

    End If

End Sub

Open in new window

0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33724182
So, in batch mode I think it looks like this.

~bp
@echo off
 
REM Specify paths to Table files to copy
TableSource=h:\source\folder\Tables
TableDest=C:\Program files\Bentley\Tables
 
REM Specify installs to perform
set InstallCommand=MSIEXEC /I
set InstallOptions=/QN /NORESTART
set InstallList=^
 "VC++DISTRIBUTABLE.MSI",^
 "SQLSERVER.MSI",^
 "RAMSS11.MSI",^
 "IEGS.MSI"
 
REM Perform each install in sequence
for %%A in (%InstallList%) do (
  %InstallCommand% %%A %InstallOptions%
)
 
REM Copy / refresh the Tables folder
if exist "%TableSource%" (
  if not exist "%TableDest%\" mkdir "%TableDest%\"
  del /Q "%TableDest%\*.*"
  xcopy /Q "%TableSource%" "%TableDest%"
)

Open in new window

0
 

Author Comment

by:Zak
ID: 33735933
I did more testing and now I have the final thing here
I have all the msi programs that I want to cascade or run them located in an UNC path on the network. The path is \\server1\project\deployment\MIS\RAM\
The command lines to run each msi file is the same with one using a different switch. These are all silent switches.
1)MSIEXEC /i"Removalofoldprogram.msi" /QN /NORESTART
1)MSIEXEC /i"Bentley IEG License Server.msi" /QN /NORESTART
2)MSIEXEC /i"SQLSERVERCE31-EN.msi" -qn
3)MSIEXEC /i"RAMSSv142.msi"
Sorry about the delay but this is what I am looking for on the script a batch file or VBS will be helpful or whatever works with SMS 2003 and can use UNC paths as described.
Thanks,
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 12

Expert Comment

by:Daz_1234
ID: 33736039
Whether it is UNC or not is no problem, just make sure you set the variables correctly in whichever version of the script, batch or VBScript, you use.

To Windows Installer (msiexec.exe) the switches -qn and /QN (and /qn and -QN) are all the same.

/norestart and /NORESTART are the same too.

All msi installs can use both /qn and /norestart, so no changes are required to the scripts.

Regards,
Daz.
0
 

Author Comment

by:Zak
ID: 33736898
Well,  
We all think that /qn and -qn is the same but SQLServerCE-EN.msi does not accept the /qn switch but it will accept the -QN.
Batch file did not like the UNC path.
Thanks,
0
 
LVL 12

Expert Comment

by:Daz_1234
ID: 33742133
Ok try this one.

I have changed the msi files to the new 4 you have given and as you can see from lines 16 - 19 you can set both the msi and the switches separately now.

Is the New Tables folder also under '\\server1\project\deployment\MIS\RAM' ?  If not you'll need to change the source for that.

Regards,
Daz.
' Install Pre-Reqs





Dim arrCmd, fso, wshShell, strProgDir, strCmd, ret

Dim strTablesSource, strTablesTarget



Set wshShell = CreateObject("WScript.Shell")

Set fso = CreateObject("Scripting.FileSystemObject")



'### Set the following lines to the location of the msi files and Tables source folder. Don't add trailing backslashes

strProgDir = "\\server1\project\deployment\MIS\RAM"

strTablesSource = "\\server1\project\deployment\MIS\RAM"

strTablesTarget = "C:\Program files\Bentley\Tables"





arrCmd = Array("Removalofoldprogram.msi", "/QN /NORESTART", _

               "Bentley IEG License Server.msi", "/QN /NORESTART", _

               "SERVERCE31-EN.msi", "-qn", _

               "RAMSSv142.msi", "")



For i = 0 To UBound(arrCmd) Step 2

    strCmd = "msiexec /i """ & strProgDir & "\" & arrCmd(i) & """ " & arrCmd(i + 1)

    ret = wshShell.Run (strCmd, 1, True)

    CheckOk strCmd, ret

Next





CopyTablesFolder()



'# End Of Script



'________________________________________

'  Subroutines

'¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯



Sub CheckOk(sCmd, iRet)

    If iRet <> 0 And iRet <> 3010 Then

        '# Error installing that component, return is not 0 or 3010 (reboot req).

        MsgBox "Error running command '" & sCmd & "'.  Return: " & iRet, vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

End Sub



Sub CopyTablesFolder()

    If Not fso.FolderExists(strTablesSource) Then

        MsgBox "Error: Source folder for Tables (" & strTablesSource & ") not found.", vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

    If fso.FolderExists(strTablesTarget) Then

        fso.DeleteFolder strTablesTarget, True

    End If

    If fso.FolderExists(strTablesTarget) Then

        MsgBox "Error: OLD target folder for Tables (" & strTablesTarget & ") not could not be deleted.", vbCritical + vbSystemModal, "ERROR"

        WScript.Quit(1)

    End If

    MakeDir strTablesTarget

    fso.CopyFolder strTablesSource, strTablesTarget

End Sub



Sub MakeDir(dir)

    If Not fso.FolderExists(dir) Then

        wshShell.Run "cmd /c MD """ & dir & """", 0, True

    End If

End Sub

Open in new window

0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 33742785
And in a BAT approach...

~bp
@echo off
  
REM Specify paths to Table files to copy
TableSource=h:\source\folder\Tables
TableDest=C:\Program files\Bentley\Tables
  
REM Specify installs to perform
set InstallList=^
 "MSIEXEC /i "Removalofoldprogram.msi" /QN /NORESTART",^
 "MSIEXEC /i "Bentley IEG License Server.msi" /QN /NORESTART",^
 "MSIEXEC /i "SQLSERVERCE31-EN.msi" -qn",^
 "MSIEXEC /i "RAMSSv142.msi""
 
REM Perform each install in sequence
for %%A in (%InstallList%) do %%A
 
REM Copy / refresh the Tables folder
if exist "%TableSource%" (
  if not exist "%TableDest%\" mkdir "%TableDest%\"
  del /Q "%TableDest%\*.*"
  xcopy /Q "%TableSource%" "%TableDest%"
)

Open in new window

0
 
LVL 12

Accepted Solution

by:
Daz_1234 earned 250 total points
ID: 33742818
===> Bill,

You might need the following changes:

Lines 3-5:
REM Specify paths to Table files to copy
Set TableSource=h:\source\folder\Tables
Set TableDest=C:\Program files\Bentley\Tables
Set ProgDir=\\server1\project\deployment\MIS\RAM

And lines 8-12:
set InstallList=^
 "MSIEXEC /i "%ProgDir%\Removalofoldprogram.msi" /QN /NORESTART",^
 "MSIEXEC /i "%ProgDir%\Bentley IEG License Server.msi" /QN /NORESTART",^
 "MSIEXEC /i "%ProgDir%\SQLSERVERCE31-EN.msi" -qn",^
 "MSIEXEC /i "%ProgDir%\RAMSSv142.msi""


Daz  :o)
0
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
ID: 33743011
Doh, missed the path to the MSI's, my bad.  And forgot the "set" all together on a couple of those lines.  And at this point I think the FOR loop over the install list is just added lines of code we don't really need.  So, for completeness, here's the updated BAT approach.

~bp
@echo off
 
REM Specify paths to Table files to copy
set TableSource=h:\source\folder\Tables
set TableDest=C:\Program files\Bentley\Tables
set ProgDir=\\server1\project\deployment\MIS\RAM
 
REM Perform each install in sequence
MSIEXEC /i "%ProgDir%\Removalofoldprogram.msi" /QN /NORESTART
MSIEXEC /i "%ProgDir%\Bentley IEG License Server.msi" /QN /NORESTART
MSIEXEC /i "%ProgDir%\SQLSERVERCE31-EN.msi" -qn
MSIEXEC /i "%ProgDir%\RAMSSv142.msi"
 
REM Copy / refresh the Tables folder
if exist "%TableSource%" (
  if not exist "%TableDest%\" mkdir "%TableDest%\"
  del /Q "%TableDest%\*.*"
  xcopy /Q "%TableSource%" "%TableDest%"
)

Open in new window

0
 

Author Closing Comment

by:Zak
ID: 33765857
good answer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now