If you need to query details of the windows registry to find an installed MSI this little method will enable you to work out the Hive that the product details are installed under, assuming you know the Product Code of the MSI. This just saves enumerating through all of the registry keys.
Look in the following registry hive:
HKLM\Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-x-x-xx\Products
You should now see a load of GUID's which are all modified Product Codes, here is how you work out the GUID.
The returned String will be the same as the Keys in the registry.
I don't know if this is useful to anyone or not and I haven't needed this code for a long time, but a previous organization needed the registry GUID in thier documentation so I put together this simple method so that I could find the details without searching the registry.
Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts
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.
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.
Subscribe to:
Posts (Atom)