Get info from MSI file.

With this script you can view which files are installed by an MSI file and which registry keys are updated. Because the output from the word11.msi became rather large, I change the output to excel. The MSI File name is an argument on the command line. To start the script type:

cscript listmsi.vbs word11.msi
'*****************************************************************
'** Script: LstMSI.vbs
'** Version: 1.0
'** Created: 1/22/2009 7:07PM
'** Author: Adriaan Westra
'** E-mail: 
'** Purpose / Comments:
'** Get file and registry info from a msi file.
'**
'**
'** Changelog :
'** 1/22/2009 7:07PM : Initial version
'** 1/25/2009 7:37PM : Changed output to Excel
'**
'*****************************************************************

Dim Version : Version = "1.0" ' Script version
Dim Author : Author = "Adriaan Westra"
Dim Email : Email = ""
Dim strFileName
Dim objXL
Dim objRng


Const xl3DPie = -4102
Const xlColumns = 2
Const xlLocationAsNewSheet = 1
Const xlColorIndexNone = -4142
Const xlLineSttyleNone = -4142
Const xlDataLabelsShowValue = 2
Const xlDataLabelsShowPercent = 3                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
Const xlDescending = 2
Const xlTopToBottom = 1
Const xlBottom = -4107
Const xlGuess = 0


'*****************************************************************
'** Add Error Handling
on error resume Next

'*****************************************************************
'** Make sure the script is started with cscript
If InStr(wscript.FullName, "wscript.exe") > 0 Then
MsgBox "Please run this script with cscript.exe." & Chr(13) & _
"For example : cscript " & WScript.ScriptName & " /?", _ 
vbExclamation, WScript.ScriptName
WScript.Quit(1)
End If

'*****************************************************************
'** Get commandline parameters
Set Args = Wscript.Arguments

If Args.Count = 0 Then
	strMsiFile = InputBox("Please give the MSI File name " & _
	"to process : ",wscript.scriptname, strPath)
Else
   If InStr(Args(0),"/?") > 0 Or InStr(UCase(Args(0)),"/H") > 0 _ 
   Or InStr(UCase(Args(0)),"/HELP") > 0 Then
      DisplayHelp
      Wscript.quit(0)
   Else
      strMsiFile = Args(0)
   End if
End if



Const msiOpenDatabaseModeReadOnly = 0 
Const msiOpenDatabaseModeTransact = 1
Const msiOpenDatabaseModeListScript = 5 


Set objMSI = CreateObject("WindowsInstaller.Installer")
Set objMsiDB = objMSI.OpenDataBase(strMsiFile, msiOpenDatabaseModeReadOnly ) : CheckError
Set objView =  objMsiDB.Openview("Select FileName From File") : CheckError
objView.Execute : CheckError
'** start excel
Set objXl = Wscript.CreateObject("Excel.application")
If objXl Is Nothing Then 
   MsgBox"Excel cannot be started.", vbInformation, Wscript.Scriptname
   Wscript.Quit
End if
With objXL
    .visible= TRUE  '** make excel visible
    .workbooks.add  '** add new workbook
    .Sheets("Sheet1").Select
    .Sheets("Sheet1").Name = "files"

    Set objRecord = objView.Fetch
    intLine = 0
    Do until objRecord is Nothing
       intLine = intLine + 1
       .activeSheet.Cells(intLine,1).Value = objRecord.StringData(1)
       ' wscript.echo objRecord.StringData(1)
       Set objRecord = objView.Fetch
    Loop
    Set objView = objMsiDB.Openview("Select * From Registry") : CheckError
    objView.Execute : CheckError
    Set objRecord = objView.Fetch
    .Sheets("Sheet2").Select
    .Sheets("Sheet2").Name = "Registry"
    
    intLine = 0
    Do until objRecord is Nothing
      intLine = intLine + 1
      Select case objRecord.IntegerData(2)
       Case -1
          strRootKey = "HKEY_CURRENT_USER"
       Case 0
          strRootKey = "HKEY_CLASSES_ROOT"
       Case 1
          strRootKey = "HKEY_CURRENT_USER"
       Case 2
          strRootKey = "HKEY_LOCAL_MACHINE"
       Case 3
          strRootKey = "HKEY_USERS"
       Case Else
          strRootKey = "Value out of range"
       End Select
       .activeSheet.Cells(intLine,1).Value = strRootKey
       .activeSheet.Cells(intLine,2).Value = objRecord.StringData(3)
       .activeSheet.Cells(intLine,3).Value = objRecord.StringData(4)
       .activeSheet.Cells(intLine,4).Value = objRecord.StringData(5)
       Set objRecord = objView.Fetch
    Loop
End With

Wscript.Quit 0

Sub CheckError
  Dim message, errRec
  If Err = 0 Then Exit Sub
  message = Err.Source & " " & Hex(Err) & ": " & Err.Description
  If Not installer Is Nothing Then
  	Set errRec = installer.LastErrorRecord
  	If Not errRec Is Nothing Then message = message & vbNewLine & errRec.FormatText
  End If
  Wscript.Echo message
  Wscript.Quit 2
End Sub
'*****************************************************************
'** Sub: DisplayHelp
'** Version: 1.0
'** Created: 24-03-2003 8:22
'** Author: Adriaan Westra
'** E-mail: 
'**
'** Purpose / Comments:
'** Display help for script
'**
'** Arguments :
'**
'** Wijzigingslog :
'** 24-03-2003 8:22 : InitiŽle versie
'**
'*****************************************************************
Sub DisplayHelp()
   strComment = string(2,"*")
   strCmntLine = String(79, "*") 
   wscript.echo strCmntline
   wscript.echo strComment
   wscript.echo strComment & " Online help for " & _ 
      Wscript.scriptname & " version : " & Version
   wscript.echo strComment
   wscript.echo strComment & " Usage : cscript " & _ 
      Wscript.scriptname & " MSI File name"
   wscript.echo strComment
   wscript.echo strComment & " Purpose : Get info from " & _
    "MSI File."
   wscript.echo strComment
   wscript.echo strComment & " Author : " & Author
   wscript.echo strComment & " E-mail : " & Email
   wscript.echo strComment
   wscript.echo strCmntline
End Sub