访问补丁信息?

时间:2011-12-23 12:39:16

标签: c# installer registry wmi patch

有谁知道,如果给定一个标识已安装产品的GUID,您可以找到使用C#为该产品安装的补丁吗?

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

我尝试了两种方法:

  1. 使用WMI我可以在Win32_Product中找到我的产品并检索 那里的信息。但是,如果我然后查询 Win32_PatchPackage或Win32_Patch用于匹配 “产品代码”。我本来期望字幕/描述 包含我想要的信息,但我得到的是另一个单独的信息 每个GUID的集合,似乎不是很明显该做什么 用它。

  2. 同样,使用注册表我可以找到产品(在 HKLM \ Software \ Microsoft \ Uninstall \\,还有一些挖掘我 可以找到补丁(在 HKLM \ SOFTWARE \微软\安装\的UserData \ S-1-5-18 \产品\) 但关键不明显。它与我的产品不一样 安装程序GUID。

  3. This question讨论了类似的问题,但提问者正在寻找Windows补丁,而我需要自己的应用程序补丁 - 所以解决方案对我来说并不适用。

    提前致谢。

1 个答案:

答案 0 :(得分:0)

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

    [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");
    }
相关问题