使用MsiGetProductInfo来检查是否安装了Microsoft Word [英] Use MsiGetProductInfo to check if Microsoft Word is installed

查看:271
本文介绍了使用MsiGetProductInfo来检查是否安装了Microsoft Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的电脑上安装了Microsoft Office 2013。
我想尝试使用 MsiGetProductInfo 查询有关该产品的信息(实际上我需要检查是否安装了Word)。



但以下C ++代码总是返回错误 1605 ERROR_UNKNOWN_PRODUCT ),这意味着该产品似乎未安装,虽然它存在于安装的应用程序列表中。

  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} 在注册表中找到 HKLM \Software \Classes \Word.Application\CLSID ,我认为它应该留在Microsoft Word应用程序 CLSID



如何正确使用 MsiGetProductInfo 安装MS Word?

解决方案

MsiGetProductInfo采用产品代码,而不是CLSID,所以这种方法不工作。如果您知道Microsoft Office使用的所有产品代码(我听说他们有数百个SKU,这可能意味着数百个或产品​​代码),您可以按顺序搜索它们。但是,除非他们只有几个产品代码,并且不添加新的(或不支持新版本),这将不会扩展。



您可能更好地遵循Word.Application类的注册表足迹回到COM服务器,以及该文件上的版本块。或者,假设它由MSI安装,您可以尝试使用 MsiEnumComponentsEx 将文件跟踪到其安装组件,以及 MsiEnumClientsEx 查找安装该组件的产品(或产品)。然后,您可以返回 MsiGetProductInfo 。 p>

请注意,这仅在通过MSI安装产品时有效,并在注册表中留下足迹。很难说是否将来的版本将遵循这种方法。很显然,并非所有现有产品都通过MSI安装:无法找到已安装的Office 2013家庭和业务与MsiEnumProducts


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.

这篇关于使用MsiGetProductInfo来检查是否安装了Microsoft Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆