Kae Travis

Editing MSI files in the Windows Installer cache

This blog entry provides an example of editing MSI files in the windows installer cache using VBScript. It follows on from the previous blog post which provided a tutorial on writing to the windows installer log file from a custom action using VBScript.

It forms part 16 of an 17-part series that explores how to use VBScript to manipulate MSI relational databases using the Windows Installer API. Throughout this series of tutorials, we identify the common issues that we encounter and the best practises that we use to overcome them.

In this example, let’s say a user has an MSI installed and they want to remove it. Every time they try to remove it, a Custom Action called ‘AlkaneCustomAction’ keeps throwing an error, and as a result the uninstall fails.

This piece of code searches all products installed or advertised for the current user and machine. When we find the product code, we open the database in trasact mode, set the condition of the Custom Action to ‘1=0’ (I.e, NEVER run it) and commit the change. The MSI will now remove without error.

Obviously this is just an example. Simply not running the Custom Action may not be the optimal solution!

Const msiOpenDatabaseModeTransact = 1  
'Enter ProductCode of the MSI we want to amend
Const ProdCodeToFind = "{00000000-0000-0000-0000-000000000000}"
Dim productCodeFound : productCodeFound = False
Dim currentProductCode, oTempDatabase
'Loop through every product, and see if the product code matches the one we're looking for
Dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")  
For Each currentProductCode In oInstaller.Products  
If currentProductCode = ProdCodeToFind Then  
oTempDatabase = oInstaller.productInfo(currentProductCode, "LocalPackage")  
productCodeFound = True
End If  
If productCodeFound Then  
Set database = oInstaller.OpenDatabase(oTempDatabase, msiOpenDatabaseModeTransact)  
Set view = database.OpenView("UPDATE `InstallExecuteSequence` SET `Condition`='1=0' WHERE `Action`='AlkaneCustomAction'")  
set view = Nothing
set database = Nothing
End If
Set oTempDatabase = Nothing
Set oInstaller = Nothing

Thanks for reading about editing MSI files in the Windows Installer cache using VBScript. Next you can find out how to find 64-bit components in an MSI database using VBScript.

Editing MSI files in the Windows Installer cache
Editing MSI files in the Windows Installer cache

Leave a Reply