September 2nd, 2005

Updated Sample MSI Scripts

Heath Stewart
Principal Software Engineer

Yesterday I blogged about what a patch file (.msp file) contains, as well as most other Windows Installer files. You might find, however, that some of the sample Windows Installer scripts in the Samples\SysMgmt\Msi\Scripts don’t work with patch files. The reason is because you must pass msiOpenDatabaseModePatchFile (32) to the Installer.OpenDatabase automation method. This corresponds to passing MSIDBOPEN_PATCHFILE to the MsiOpenDatabase function.

Two scripts in particular that are helpful for enumerating streams and storages in a package are WiStream.vbs and WiSubStg.vbs, and the necessary change to conditionally pass msiOpenDatabaseModePatchFile is a simple change, as shown below for WiStream.vbs:

13a14
> Const msiOpenDatabaseModePatchFile    = 32
50a52
> Dim patchMode : If LCase(GetExtension(databasePath)) = “.msp” Then patchMode = msiOpenDatabaseModePatchFile Else patchMode = 0
63c65
< Dim database : Set database = installer.OpenDatabase(databasePath, openMode) : CheckError

> Dim database : Set database = installer.OpenDatabase(databasePath, openMode + patchMode) : CheckError
104a107,116
>
> Function GetExtension(path)
>     Dim dot : dot = InStrRev(path, “.”)
>     Dim bslash : bslash = InStrRev(path, “\”)
>     If dot > bslash Then
>         GetExtension = Mid(path, dot)
>     Else
>         GetExtension = Empty
>     End If
> End Function

You can download a ZIP archive of diff-style patch files for both scripts (like the example above), or you can download and install a small patch for the most recent Platform SDK. This patch is not supported by Microsoft, but if you have any problems please let me know. It simply updates the two aforementioned script files and you can remove it at any time from the Add/Remove Programs (ARP) control panel.

Update: Install the MSP by extracting it from the ZIP archive, then open a command window and type the following command:

msiexec.exe /p "[path to msp]Scripts.msp" /qb+

Author

Heath Stewart
Principal Software Engineer

Heath is an application architect and developer, looking to help educate others to learn professional development. Besides designing and developing applications he enjoys writing about intermediate and advanced topics. Heath also consults for deployment packages and scenarios within Microsoft and for external customers.

0 comments

Discussion are closed.