gpt4 book ai didi

winapi - 查找已安装产品的所有组件

转载 作者:行者123 更新时间:2023-12-02 00:28:31 25 4
gpt4 key购买 nike

我正在使用 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);

最佳答案

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

关于winapi - 查找已安装产品的所有组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7897065/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com