Accessing .MSI-file As a Database


I believe you know that .MSI installation file is a database, so that theoretically you can use the SQL statements to manage it.  It would be very nice to use something like SELECT * FROM Property to see all the names of the parameters which can be passed through MsiExec. The links below contain a a lot of useful information:

I have created a small script, which can be used to access any table in .MSI file. However, I use it just to read the names of the properties. I select only uppercase property names because only such properties can be changes through the MsiExec command line.

Here is the script:

MSIFileName = “MyMSI.msi”        #Full Path to .msi file
$WindowsInstaller = New-Object -com WindowsInstaller.Installer
$Database = $WindowsInstaller.GetType().InvokeMember(“OpenDatabase”, “InvokeMethod”, $Null, $WindowsInstaller, @($MSIFileName,0))
$View = $Database.GetType().InvokeMember(“OpenView”, “InvokeMethod”, $Null, $Database, (“SELECT * FROM Property”))
$View.GetType().InvokeMember(“Execute”, “InvokeMethod”, $Null, $View, $Null)

$Record = $View.GetType().InvokeMember(“Fetch”, “InvokeMethod”, $Null, $View, $Null)

while($Record -ne $Null)
{
$PropertyName = $Record.GetType().InvokeMember(“StringData”, “GetProperty”, $Null, $Record, 1)
if (-not ($PropertyName -cmatch “[a-z]”))
{
$PropertyValue = $Record.GetType().InvokeMember(“StringData”, “GetProperty”, $Null, $Record, 2)
Write-Host ($PropertyName + ” = ” + $PropertyValue)
}
$Record = $View.GetType().InvokeMember(“Fetch”, “InvokeMethod”, $Null, $View, $Null)
}

Advertisements

4 Responses to Accessing .MSI-file As a Database

  1. […] After a bit of research I found a way to do this in PowerShell proper. I adapted code from his blog entry. […]

  2. There is certainly a lot to find out about this topic.
    I really like all of the points you have made.

  3. Ahaa, its good dialogue on the topic of this piece of writing at
    this place at this weblog, I have read all that,
    so now me also commenting at this place.

  4. Dope try bro. Love the effort.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: