Solved

Vbs script or Batch file help

Posted on 2010-09-19
14
449 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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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
Comment Utility
BillPrew,
On SMS when the package gets replicated to distribution points how does the batch file behaves?
Thanks,
0
 

Author Comment

by:Zak
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 12

Expert Comment

by:Daz_1234
Comment Utility
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
Comment Utility
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
Comment Utility
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 51

Expert Comment

by:Bill Prew
Comment Utility
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
Comment Utility
===> 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 51

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points
Comment Utility
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
Comment Utility
good answer
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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