vbscriptwindows-installermsitransform

How to get MST properties from vbscript


So, I am creating a vbscript that will read an MSI and MST file. The idea is that if the user that will run the script is testing an MSI with an MST file involved, the script should create a "report" of the new properties that this MST have.

I am able to get the properties from a regular MSI, the problem is when I am trying to get into the MST section. While doing research I found out about the _TransformView Table and this should help me to obtain this information but I think I am not sure I know how to handle that table.

Const msiTransformErrorViewTransform = 256

Const msiOpenDB = 2

Dim FS, TS, WI, DB, View, Rec

Set WI = CreateObject("WindowsInstaller.Installer")

Set DB = WI.OpenDatabase(msiPath,msiOpenDB)

DB.ApplyTransform mstPath, msiTransformErrorViewTransform 

If Err.number Then 
    Exit Function 
End If

For i = 0 To 24 'Number of properties on the arrPropertyList

    Set View = DB.OpenView("Select `Value` From Property WHERE `Property` = " & "'" & arrPropertyList(i) & "'")
    View.Execute
    Set Rec = View.Fetch
    If Not Rec Is Nothing Then
        objLog.WriteLine arrPropertyList(i) & " = " & Rec.StringData(1)
    End If

Next

That code will display the msi properties that I have added on the arrPropertyList. The thing is that I am looking for the MST properties and I am only getting the MSI ones. I know that I should change the Query to access the _TransformView Table when calling the DB.OpenView but not sure how can I get to this information! Any knowledge you can share would be welcome.


Solution

  • It works slightly differently to what you think. Run the following to see what I mean (maybe force the VBS to run with Cscript.exe from a command prompt if you're expecting a lot of output):

    'create 2 constants - one for when we want to just query the MSI (read) and one for when we want to make changes (write)
    
    Const msiOpenDatabaseModeReadOnly = 0
    Const msiOpenDatabaseModeTransact = 1
    Const msiTransformErrorViewTransform = 256
    
    'create WindowsInstaller.Installer object
    Dim oInstaller : Set oInstaller = CreateObject("WindowsInstaller.Installer")
    
    'open the MSI (the first argument supplied to the vbscript)
    Dim oDatabase : Set oDatabase = oInstaller.OpenDatabase("C:\Temp\Temp.msi",msiOpenDatabaseModeReadOnly) 
    
    oDatabase.ApplyTransform "C:\Temp\Temp.mst", msiTransformErrorViewTransform 
    
    'create a view of the registry we want to see
    Dim sql : sql = "SELECT * FROM `_TransformView`"
    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
        wscript.echo "Table: " & regRecord.StringData(1) 
        wscript.echo "Column: " & regRecord.StringData(2) 
        wscript.echo "Row: " & regRecord.StringData(3) 
        wscript.echo "Data: " & regRecord.StringData(4)
        wscript.echo "Current: " & regRecord.StringData(5)
        wscript.echo "***"
    
        'go and fetch the next row of data  
        Set regRecord = regView.Fetch
    Wend
    
    regView.Close
    Set regView = Nothing
    Set regRecord = Nothing
    Set oDatabase = Nothing
    Set oInstaller = Nothing
    

    So if you only wanted to see changes in the Property table, you would change the SQL query to:

    Dim sql : sql = "SELECT * FROM `_TransformView` WHERE `Table` = 'Property'"
    

    As well as storing the column names of the changed entries, the 'Column' column in the '_TransformView' table also stores whether the value was inserted, removed etc by using the values: INSERT, DELETE, CREATE, or DROP.

    You can find lots of VBScript Windows Installer tutorials for reference - don't forget to set your objects to Nothing otherwise you'll leave handles open. And of course use the link you provided for further reference.