The VBScript function below can be used to retrieve MSI properties from an MSI file (database). It uses the WindowsInstaller.Installer class.
Function GetMsiProperty(msiFile, strProperty)
On Error Resume Next
dim inst, db, view, row, str
str = ""
set inst = Wscript.CreateObject("WindowsInstaller.Installer")
Set db = inst.OpenDatabase(msiFile,0)
If Err.number Then
'error
Else
Set view = db.OpenView("Select `Value` From Property WHERE `Property` ='"& strProperty & "'")
view.Execute
Set row = view.Fetch
If Not row Is Nothing Then str=row.StringData(1)
End If
set row = Nothing
set view = Nothing
set db = Nothing
set inst = Nothing
On Error Goto 0
GetMsiProperty = str
End Function
This function accepts the MSI full file path, and the property to be retrieved.
For example, in order to retrieve the ProductCode of an MSI whose full path is C:\Temp\Test.msi, one would call it like this:
strProductCode = GetMsiProperty("C:\Temp\Test.msi", "ProductCode")
If the property doesn’t exist, or if the file cannot be opened, the function will return an empty string “”.