Link to home
Start Free TrialLog in
Avatar of smart Z
smart Z

asked on

Vbs script or Batch file help

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
Avatar of Bill Prew
Bill Prew

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

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

Avatar of smart Z

ASKER

BillPrew,
On SMS when the package gets replicated to distribution points how does the batch file behaves?
Thanks,
Avatar of smart Z

ASKER

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
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

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

Avatar of smart Z

ASKER

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,
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.
Avatar of smart Z

ASKER

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,
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

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

ASKER CERTIFIED SOLUTION
Avatar of Darren Collins
Darren Collins
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of smart Z

ASKER

good answer