wixinstallationwindows-installerdtf

How can I programmatically read the properties inside an MSI file?


Is there a way to read the properties inside an MSI file?

For example, given a MSI file named Testpackage.msi, I need to find

productName
PackageCode
version

This I am going to use it with WMI uninstall

string objPath = string.Format("Win32_Product.IdentifyingNumber='{0}', Name='{1}', Version='{2}'", "{AC9C1263-2BA8-4863-BE18-01232375CE42}", "testproduct", "10.0.0.0");

Using Orca is a great option, if this can be achieved programmatically. Then I can use this to generate automatic release notes. And in un-installing program too.


Solution

  • You can use the COM-based API for working with MSI, and do something like

    Function GetVersion(ByVal msiName)
    
        Const msiOpenDatabaseModeReadOnly = 0
        Dim msi, db, view
    
        Set msi = CreateObject("WindowsInstaller.Installer")
        Set db = msi.OpenDataBase(msiName, msiOpenDatabaseModeReadOnly)
        Set view = db.OpenView("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductVersion'")
        Call view.Execute()
    
        GetVersion = view.Fetch().StringData(1)
    
    End Function