Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

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
0
Habib Z
Asked:
Habib Z
  • 5
  • 5
  • 4
2 Solutions
 
Bill PrewCommented:
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
 
Daz_1234Commented:
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
 
Habib ZNetwork AnalystAuthor Commented:
BillPrew,
On SMS when the package gets replicated to distribution points how does the batch file behaves?
Thanks,
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Habib ZNetwork AnalystAuthor Commented:
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
 
Daz_1234Commented:
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
 
Bill PrewCommented:
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
 
Habib ZNetwork AnalystAuthor Commented:
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
 
Daz_1234Commented:
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
 
Habib ZNetwork AnalystAuthor Commented:
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
 
Daz_1234Commented:
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
 
Bill PrewCommented:
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
 
Daz_1234Commented:
===> 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
 
Bill PrewCommented:
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
 
Habib ZNetwork AnalystAuthor Commented:
good answer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now