How to retrieve the PackageCode from an MSI file programatically

In addition to our VBScript function that retrieves Property Values from an MSI database, we might need to read the PackageCode, from the MSI Summary view. For that, we could use the code below.

Function GetMsiPackageCode(msiFile)
	On Error Resume Next
	dim inst, summary, view, row, str
	str = ""
	set inst = Wscript.CreateObject("WindowsInstaller.Installer") 
	set summary = inst.SummaryInformation(msiFile)	
	If Err.number Then 
		str  =  summary.Property(9) ' PID_REVNUMBER = 9, package code.
	End If
	set summary = Nothing
	set inst = Nothing
	On Error Goto 0
	GetMsiPackageCode = str
End Function

To use it, we’d simply call GetMsiPackageCode(“C:\Temp\Test.msi”) and store it into a (string) variable.