Search for a File Inside a Merge Module

Sometimes I need to search for a file inside a merge module (MSM). Since I don’t know which specific merge module I’m looking for, I wrote this script to iterate through every merge module in a specific folder to find a specific file in the File table.

Search for a File Inside a Merge Module

CScript.exe {Script} {FileToSearchFor}

Const msiOpenDatabaseModeReadOnly = 0
Const msiOpenDatabaseModeTransact = 1
'create WindowsInstaller.Installer object
dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")
dim fileName : fileName = wscript.arguments(0)
Const ForReading = 1
Const ForWriting = 2
sFolder = "C:\Program Files\InstallShield\2013\Objects"
Set oFSO = CreateObject("Scripting.FileSystemObject")
For Each oFile In oFSO.GetFolder(sFolder).Files
'open the MSI (the first argument supplied to the vbscript)
Dim oDatabase : Set oDatabase = oInstaller.OpenDatabase(oFile.Path,msiOpenDatabaseModeReadOnly) 
'create a view of the registry we want to see
Dim sql : sql = "SELECT `FileName` FROM `File`"
Dim regView : Set regView = oDatabase.OpenView(sql)
'execute the query
regView.Execute 
'fetch the first row of data (if there is one!)
Dim regRecord : Set regRecord = regView.Fetch
'whilst we've returned a row and therefore regRecord is not Nothing
While Not regRecord Is Nothing
'print out the registry key
If instr(regRecord.StringData(1),fileName) > 0 Then		
wscript.echo "File " & fileName & " is in MSM: " & oFile.Path
End If
'go and fetch the next row of data	
Set regRecord = regView.Fetch
Wend
regView.Close
Set regView = Nothing
Set regRecord = Nothing
Set oDatabase = Nothing
Next
Set oInstaller = Nothing
Set oFSO = Nothing