有人成功使用过 WMI Win32_PatchPackage 类吗? (C#)

发布于 2024-08-14 21:56:37 字数 1864 浏览 1 评论 0原文

根据来源此处这里,这个类应该给我一个很好的、人类可读的列表适用于 Windows 的补丁。我想要的是应用于远程计算机的 KB 补丁列表。

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"]);
}

相反,我得到的是这个类似 GUID 的大杂烩。我是否在错误的地方寻找东西?

{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...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-08-21 21:56:37

就其价值而言,这正是我所看到的。我已经在 Win7 和 Vista 机器上尝试过此代码。两者都是 64 位机器。两者都产生了大量的 GUID。

我还尝试安装 WMI 工具...

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

...这些显示完全相同的事情。

如果您希望枚举计算机上安装的修补程序和补丁,那么您可能需要查看 Win32_QuickFixEngineering 类。如果您更改代码以便从此对象中进行选择...

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

...并打印出 HotFixID 和说明...

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

...那么您可能会得到您想要的东西。我看到这样的行...

KB975467:
http://support.microsoft.com/?kbid=975467
:安全更新

KB975517:
http://support.microsoft.com/?kbid=975517
:安全更新

KB976325:
http://support.microsoft.com/?kbid=976325
:安全更新

本页...

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

...有一些很好的示例,并且此页面...

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

... 描述 Win32_QuickFixEngineering 类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文