I know I'm supposed to have retired from ITN but well, I thought I'd share one last thing.

When you're writing scripts or adding MSIs to SCCM or whatever, what a monumental pain it is to have to load the MSI into Orca/InstEdit, scroll to the Properties table then scroll to the ProductCode property, eh? Well, no more! Here's a script which will echo that property to the screen and copy it to the clipboard, ready for pasting to...wherever you fancy. Plus, I've even created a .REG for you that adds the script to Explorer's context menu. Obviously, you'll need to edit the script path in the .REG.

To answer the inevitable question, no, there is no guarantee, warranty or support of any kind.


@="Get Product &Code"

@="cscript c:\\windows\\syswow64\\GetProductCode.VBS \"%1%\""


Option Explicit

Dim blnResult
Dim strMSI
Dim strCode

strMSI   = WScript.Arguments(0)
If Len(strMSI) = 0 Then
End If

blnResult  = GetMSIProductCode(strMSI, strCode)
If blnResult Then
 WScript.Echo strMSI & "'s ProductCode is " & strCode
 blnResult = CopyToClipboard(strCode)
End If

Function GetMSIProductCode(ByVal strMSIFile, ByRef strProductCode)
 Const intMSI_OpenDatabaseModeReadOnly  = 0  '// Opens a database read-only, no persistent changes
 Const intMSI_OpenDatabaseModeTransact  = 1  '// Opens a database read/write in transaction mode
 Const intMSI_OpenDatabaseModeDirect  = 2  '// Opens a database direct read/write without transaction
 Const intMSI_OpenDatabaseModeCreate  = 3  '// Creates a new database, transact mode read/write
 Const intMSI_OpenDatabaseModeCreateDirect = 4  '// Creates a new database, direct mode read/write
 Const intMSI_OpenDatabaseModeListScript  = 5  '// Opens a database to view advertise script files, such as the files generated by the CreateAdvertiseScript method
 Const intMSI_OpenDatabaseModePatchFile  = 32  '// Adds this flag to indicate a patch file

 GetMSIProductCode = False
 If strMSIFile = "" Then
  Exit Function
 End If
 Dim objInstaller
 Dim objDatabase
 Dim objView
 Dim objRecord

 On Error Resume Next
 Set objInstaller  = CreateObject("WindowsInstaller.Installer")
 If Not IsObject(objInstaller) Then
  Exit Function
 End If
 Set objDatabase  = objInstaller.OpenDatabase(strMSIFile, intMSI_OpenDatabaseModeReadOnly)
 If Err.Number Then
  Exit Function
 End If
 Set objView   = objDatabase.OpenView("Select `Value` From Property WHERE `Property` ='ProductCode'")

 Set objRecord   = objView.Fetch
 If Not objRecord Is Nothing Then
  strProductCode = objRecord.StringData(1)
  GetMSIProductCode = True
 End If

 Set objRecord   = Nothing
 Set objView   = Nothing
 Set objDatabase  = Nothing
 Set objInstaller  = Nothing
End Function

Function CopyToClipboard(ByVal strText)
 Dim objIE
 CopyToClipboard   = False
 Set objIE    = CreateObject("InternetExplorer.Application")
 If Not IsObject(objIE) Then
  Exit Function
 End If
 With objIE
  .document.parentwindow.clipboardData.SetData "text", strText
 End With
 CopyToClipboard   = True
 Set objIE    = Nothing
End Function