如何获取某个路径中的WMI类列表(使用C#)?

时间:2014-08-10 15:08:51

标签: c# wmi wmi-query

使用C#,如何获取特定路径中WMI个班级的列表,例如root\WMI

1 个答案:

答案 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);