1

这是我的代码,我从您的一个问题中复制而来,代码是:

class Program
{
    static void Main(string[] args)
    {
        try
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\WMI","SELECT * FROM MSWmi_PnPInstanceNames");


            foreach (ManagementObject queryObj in searcher.Get())
            {
                Console.WriteLine("-----------------------------------");
                //Console.WriteLine("MSWmi_PnPInstanceNames instance");
                //Console.WriteLine("-----------------------------------");
                Console.WriteLine("InstanceName: {0}", queryObj["InstanceName"]);

            }

            Console.Read();

        }
        catch (ManagementException e)
        {
            MessageBox.Show("An error occurred while querying for WMI data: " + e.Message);
        }
    }

}

现在,我的问题是:queryObj 数组的元素是什么?

4

1 回答 1

1

ManagementObjectSearcher.Get()方法返回类型是ManagementObjectCollection.

此集合中的对象属于ManagementBaseObject 派生类型,包括ManagementObjectManagementClass

ManagementObjectSearcher.Get()方法;

调用指定的 WMI 查询并返回结果集合。

InstanceNameproopertyName例如ManagementObject从方法返回ManagementObjectSearcher.Get

于 2013-05-08T06:17:55.853 回答