Solved

Vbs script or Batch file help

Posted on 2010-09-19
14
461 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
14 Comments
 
LVL 54

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 13

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 13

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 54

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

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 13

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 54

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 13

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 54

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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