有人成功使用过 WMI Win32_PatchPackage 类吗? (C#)
根据来源此处和这里,这个类应该给我一个很好的、人类可读的列表适用于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
就其价值而言,这正是我所看到的。我已经在 Win7 和 Vista 机器上尝试过此代码。两者都是 64 位机器。两者都产生了大量的 GUID。
我还尝试安装 WMI 工具...
http://www.microsoft.com/downloads/details.aspx?familyid=6430F853-1120-48DB-8CC5-F2ABDC3ED314&displaylang=en
...这些显示完全相同的事情。
如果您希望枚举计算机上安装的修补程序和补丁,那么您可能需要查看 Win32_QuickFixEngineering 类。如果您更改代码以便从此对象中进行选择...
...并打印出 HotFixID 和说明...
...那么您可能会得到您想要的东西。我看到这样的行...
本页...
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...
... and print out the HotFixID and Description...
... then you might get what you're after. I see rows like this...
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.