使用C#
,如何获取特定路径中WMI
个班级的列表,例如root\WMI
?
答案 0 :(得分:2)
这可能对您有所帮助
http://msdn.microsoft.com/en-US/library/ms257362%28v=vs.80%29.aspx
修改强>
在函数AddClassesToList
上private void AddClassesToList(object o)
{
this.statusValue.Text = "Searching...";
try
{
// Perform WMI object query on
// selected namespace.
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
new ManagementScope(
namespaceValue.Text),
new WqlObjectQuery(
"select * from meta_class"),
null);
foreach (ManagementClass wmiClass in
searcher.Get())
{
this.classList.Items.Add(
wmiClass["__CLASS"].ToString());
count++;
}
this.statusValue.Text =
count + " classes found.";
}
catch (ManagementException ex)
{
this.statusValue.Text = ex.Message;
}
}
这部分:
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(
new ManagementScope(
"root/default"/*Replace this with your namespace*/),
new WqlObjectQuery(
"select * from meta_class"),
null);