alice7
alice7

Reputation: 3880

Get Product Version using upgrade code for a product installed

I am trying to retrieve the product version of an installed msi using upgrade code. I tried using MsiGetProductInfo api but it doesn't return me the result.

I couldn't find the application under HKEY_LOCAL_MACHINE\SOFTWARE\MSFT\Windows\CurrentVersion\Uninstall.

But Instead I did find my application some place else in registry under Installer\Products.

I know that similar question has bben asked here: Get Product Code of installed Msi

but does someone has a better way of doing it.

Thanks

Upvotes: 2

Views: 3092

Answers (1)

Greg
Greg

Reputation: 946

I had pretty much the same issue just now. If you have the upgrade-code GUID, you can do this:

WindowsInstaller.Installer installer =
   Activator.CreateInstance(/* left as an exercise for the reader */);
foreach (string productCode in installer.get_RelatedProducts("your-upgradecode-guid")) {
   string productVersion = installer.get_ProductInfo(productCode, "VersionString");
}

Trouble is, there could be multiple related products, so how you handle that is up to you.

EDIT: If you install per-user by default or by mistake, then you might not get the product code with RelatedProducts if you run the query as a different user than the MSI was installed for... even if the installation was more or less public.

Upvotes: 2

Related Questions