【问题标题】:Accessing Patch Information?访问补丁信息?
【发布时间】:2011-12-23 12:39:16
【问题描述】:

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

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

我尝试了两种方法:

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

  2. 同样,使用注册表我可以找到产品(在 HKLM\Software\Microsoft\Uninstall\\,并进行了一些挖掘 可以找到补丁(在 HKLM\Software\Microsoft\Installer\UserData\S-1-5-18\Products\) 但关键并不明显。和我的产品不一样 安装程序 GUID。

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

提前致谢。

【问题讨论】:

    标签: c# installation registry wmi patch


    【解决方案1】:

    我可以通过将从 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");
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-19
      • 2011-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多