Freigeben über


Running chained MSI installations

Anyone who has tried to run two Windows Installer-based installations at the same time knows that you can't do this. Only one MSI-based installation can run at a time. So what if you need to run multiple MSI packages one after the other? There is an easy solution to this using vbscript.

Consider the following code:

' ===================================================================== 

Option Explicit

runit()

sub runit()

Dim ret, oInstaller

Set oInstaller = CreateObject("WindowsInstaller.Installer")

ret = oInstaller.InstallProduct("c:\Testsetupfiles\testsetup1.msi", "")

ret = oInstaller.InstallProduct("c:\Testsetupfiles\testsetup2.msi", "")

ret = oInstaller.InstallProduct("c:\Testsetupfiles\testsetup3.msi", "")

end sub
' ==========================================================================

What we're doing here is simple. We create variables ret and oInstaller and then set oInstaller to an instance of a Windows Installer object. Then we use the WindowsInstaller.InstallProduct method to call the installations. Since we have three lines of code here making the call, we're running three different installations as you can see by the different file names. The last two lines beginning with "ret =" wait until the line above it has run completely to start the installation. This script allows you to specify a local directory where your MSI file resides or you can specify a UNC path such as \\ServerName\ServerShare\MSIName

You can also expand on the above code to run the installations of all MSI files in a shared folder on the client machine. Consider the following:

' ==========================================================================

Option Explicit

runit()

sub runit()
 On Error resume next
 dim FSO, ret, oInstaller
 dim fn, f, fc

 Set FSO = CreateObject("Scripting.FileSystemObject")
 Set oInstaller = CreateObject("WindowsInstaller.Installer")

 set f = fso.getfolder("C:\Testsetupfiles")
 set fc = f.files

 for each fn in fc
  ret = oInstaller.InstallProduct(f & "\" & fn.name & "", "")
 Next

end sub

' ==========================================================================

Though it looks more complex, it really isn't. We're setting instances of the File System Object (FSO) and Windows Installer (oInstaller) and declaring variables we'll need to ennumerate the files in the target directory.
We set f equal to our target folder C:\TestSetupFiles. Again, this can be substituted for a UNC path to a share on the network. Then we set fc to all of the files in our directory (f). Finally, by using a for each loop we cycle through all of the files (fc), setting the currently cycled file to fn and then call the WindowsInstaller.InstallProduct method to run the installation. In this line of code

ret = oInstaller.InstallProduct(f & "\" & fn.name & "", "")

we're parsing the directory f, adding a backslash and then ending with the filename (fn.name). This will work for all MSI files in a given directory. I added the On Error Resume Next line in the code because it's possible you will have more than just MSI files in the specified folder and obviously you can't install a .TXT file.

Comments

  • Anonymous
    September 13, 2010
    What do you need to add in order to make these msi installs all silent and no restart? I have tried the same way i would do it with a standard batch file and it hasnt worked. Thanks