访问补丁信息

本文关键字:信息 补丁 访问 | 更新日期: 2023-09-27 18:18:45

有没有人知道,给定一个GUID来标识一个已安装的产品,你如何用c#找到该产品安装的补丁?

应用程序相当复杂,我们不时通过Orca/MSI创建补丁(MSP文件)。这些补丁可以安装在客户的计算机上,然后可以在程序和功能下的"查看已安装的更新"中查看。

我试过两种方法:

  1. 使用WMI,我可以在Win32_Product中找到我的产品并检索信息。但是,如果我然后查询Win32_PatchPackage或Win32_Patch用于匹配"ProductCode的"。我希望标题/描述包含了我想要的信息,但我得到的只是另一个单独的信息每个guid的集合,这似乎不是很明显要做什么用它。

  2. 同样,使用注册表我可以找到产品(在HKLM'Software'Microsoft'Uninstall',并与一些挖掘我可以找到补丁(在微软HKLM ' Software ' '安装'用户数据产品' S-1-5-18 ' ')但关键并不明显。这和我的产品不一样安装程序GUID。

这个问题讨论了类似的问题,但是提问者在寻找Windows补丁,而我需要我自己的应用程序补丁-所以这个解决方案并不适合我。

提前感谢。

访问补丁信息

我能够通过将从Win32_PatchPackage返回的ProductCode插入到Win32 dll中,然后使用as来实现这一点。

    [DllImport("msi.dll", CharSet = CharSet.Unicode)]
    internal static extern Int32 MsiGetPatchInfoEx(string szPatchCode, string szProductCode, string szUserSid, int dwContext, string szProperty, [Out] StringBuilder lpValue, ref Int32 pcchValue);
    // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa370128%28v=vs.85%29.aspx 
    // for valid values for the property paramater
    private static string getPatchInfoProperty(string patchCode, string productCode, string property)
    {
        StringBuilder output = new StringBuilder(512);
        int len = 512;
        MsiGetPatchInfoEx(patchCode, productCode, null, 4, property, output, ref len);
        return output.ToString();
    }
    public static string GetPatchDisplayName(string patchCode, string productCode)
    {
        return getPatchInfoProperty(patchCode, productCode, "DisplayName");
    }