Has anyone successfully used the WMI Win32_PatchPa

2019-08-02 11:15发布

According to sources here and here, this class should give me a nice and human-readable list of patches applied to Windows. What I want is a list of KB patches applied to a remote machine.

ManagementScope scope;
ConnectionOptions options = new ConnectionOptions();
options.Username = tbUsername.Text;
options.Password = tbPassword.Password;
options.Authority = String.Format("ntlmdomain:{0}", tbDomain.Text);
scope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", tbHost.Text), options);
scope.Connect();
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, new ObjectQuery("SELECT * FROM Win32_PatchPackage"));
foreach (ManagementObject queryObj in searcher.Get())
{
    wmiResults.Text += String.Format("{0}: {1} {2}\n",
                                     queryObj["PatchID"],
                                     queryObj["Caption"],
                                     queryObj["Description"]);
}

Instead, what I get is this GUID-like smorgasbord. Am I looking for things in the wrong place?

{0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B}: {0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B} {0B36C6D6-F5D8-4EAF-BF94-4376A230AD5B}
{3D019598-7B59-447A-80AE-815B703B84FF}: {3D019598-7B59-447A-80AE-815B703B84FF} {3D019598-7B59-447A-80AE-815B703B84FF}
{5ECEB317-CBE9-4E08-AB10-756CB6F0FB6C}: {5ECEB317-CBE9-4E08-AB10-756CB6F0FB6C} {5ECEB317-CBE9-4E08-AB10-756CB6F0FB6C}
{69F52148-9BF6-4CDC-BF76-103DEAF3DD08}: {69F52148-9BF6-4CDC-BF76-103DEAF3DD08} {69F52148-9BF6-4CDC-BF76-103DEAF3DD08}
{71127777-8B2C-4F97-AF7A-6CF8CAC8224D}: {71127777-8B2C-4F97-AF7A-6CF8CAC8224D} {71127777-8B2C-4F97-AF7A-6CF8CAC8224D}
{7559E742-FF9F-4FAE-B279-008ED296CB4D}: {7559E742-FF9F-4FAE-B279-008ED296CB4D} {7559E742-FF9F-4FAE-B279-008ED296CB4D}
...etc...

标签: c# wmi
1条回答
做个烂人
2楼-- · 2019-08-02 12:07

For what it's worth, this is exactly what I see. I've tried this code on a Win7 and a Vista mechine. Both are 64 bit machines. Both produced a sea of GUIDs.

I also tried installing the WMI Tools...

http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en

... and these show the exact same thing.

If you're looking to enumerate the hotfixes and patches installed on the machine then you might want to look at the Win32_QuickFixEngineering class instead. If you change you code so that select from this object...

ManagementObjectSearcher searcher = new ManagementObjectSearcher(new ObjectQuery("select * from Win32_QuickFixEngineering"));

... and print out the HotFixID and Description...

Console.WriteLine("{0}: {1} : {2} \n", queryObj["HotFixID"], queryObj["Caption"], queryObj["Description"]);

... then you might get what you're after. I see rows like this...

KB975467: http://support.microsoft.com/?kbid=975467 : Security Update

KB975517: http://support.microsoft.com/?kbid=975517 : Security Update

KB976325: http://support.microsoft.com/?kbid=976325 : Security Update

This page...

http://msdn.microsoft.com/en-us/library/aa394596(VS.85).aspx

... has some good samples, and this page...

http://msdn.microsoft.com/en-us/library/aa394391(VS.85).aspx

... describes Win32_QuickFixEngineering class.

查看更多
登录 后发表回答