There is installed Microsoft Office 2013 on my PC.
I'm trying to use MsiGetProductInfo to query information about that product (actually I need to check if Word is installed).
But the following C++ code always returns with an error 1605
(ERROR_UNKNOWN_PRODUCT
) which means that the product appears to be not installed, although it is present in the list of installed applications.
TCHAR szVersion[20];
DWORD cchVersion = 20;
LSTATUS st = MsiGetProductInfo(TEXT("{000209FF-0000-0000-C000-000000000046}"), INSTALLPROPERTY_VERSIONSTRING, szVersion, &cchVersion);
ClassID {000209FF-0000-0000-C000-000000000046}
is found in the registry in HKLM\Software\Classes\Word.Application\CLSID
and I suppose it should stay for Microsoft Word Application CLSID
.
How to use MsiGetProductInfo
correctly in order to check that MS Word is installed?
MsiGetProductInfo takes product codes, not CLSIDs, so this approach will not work. If you know all the product codes that are in use by Microsoft Office (I hear they have hundreds of SKUs, which could mean hundreds or product codes), you could search for them all sequentially. But, unless they only have a couple product codes, and don't add new ones (or you don't support new versions), this will not scale.
You may be better off following the registry footprint for the Word.Application class back to a COM server, and the version block on that file. Or, assuming it's installed by an MSI, you could try to use MsiEnumComponentsEx to trace the file to its installing component, and MsiEnumClientsEx to find the product (or products) that installed that component. And from there you could return to MsiGetProductInfo.
Note that this only works when the product was installed via MSI, and leaves a footprint in the registry. It's hard to say for certain whether future versions will follow this approach. Apparently not all existing products install via MSI: Can't find installed Office 2013 Home and business with MsiEnumProducts.
These links might help:
How to detect installed version of MS-Office?
and there is also a collection of articles like this one, and these seem to indicate that the ProductCode isn't the best indicator because of differences in Betas etc.
You also need to worry about 32-bit and 64-bit versions of office, so this may be useful too:
Detect whether Office is 32bit or 64bit via the registry