【问题标题】:Find all the components of an installed product查找已安装产品的所有组件
【发布时间】:2011-10-25 23:32:03
【问题描述】:

我正在使用 msi windows api 以编程方式管理一些已安装的程序。

我知道Product 代码,但我希望找到与此产品相关的所有Components

我知道如何枚举系统中的所有组件,并查询组件的产品代码。因此,一个明显的解决方案是遍历所有这些组件,并对产品 ID 执行字符串比较。 (见下面的代码)。

但这表现不佳。在我的机器上,这段代码正在搜索 37,601 个组件以找到匹配的 8 个组件。

是否有一些 API 调用,给定产品标识符,只列出该产品的组件?

do
{
    // productGuid is a std::wstring
    TCHAR componentBuffer[39];
    msiReturn = ::MsiEnumComponents(componentIndex++, componentBuffer);
    if(msiReturn != ERROR_NO_MORE_ITEMS)
    {
        TCHAR productBuffer[39];
        UINT productReturnCode = ::MsiGetProductCode(componentBuffer, productBuffer);
        if(productGuid == productBuffer)
        {
            // Add this to the matching component ids
        }
    }
}
while (msiReturn != ERROR_NO_MORE_ITEMS);

【问题讨论】:

    标签: winapi windows-installer


    【解决方案1】:

    查看 MsiGetProductInfo 函数及其 INSTALLPROPERTY_LOCALPACKAGE 属性。这应该能够为您返回 [WindowsFolder]Installer 中缓存的 MSI 的路径,并且您应该能够从那里使用 MsiOpenDatabase 和其他相关函数来查询组件表以获取您正在寻找的信息。

    【讨论】:

      猜你喜欢
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 2014-08-18
      • 2014-11-15
      • 2015-07-08
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多