Wednesday, 24 August 2011

Query an MSI database from C#

Some simple code to enable querying an MSI database from C#

A simple connection method that returns a True or False depending on the success of connecting, the Filename is retrieved from an input box on the main form called "txtSource" and sets the global variable msiDatabase.
You will need to add the reference to "Microsoft Windows Installer Object Library" or "C:\Windows\System32\MSI.dll"



And here is a simple SQL query to pull out a value from the property table.

The same code can be used in a windows form application or you could create a simple command line utility to return a property value.

1 comment:

  1. Thanks for the solution! This one finally works, not giving me any cryptical COM error on view.Fetch call.

    Only you need to add break; to exit the property lookup loop when the property is actually found.

    Vlasta

    ReplyDelete