头条 科技 产经 家电 智能 手机 芯片 数码 电商 WAP版
中国IT产经新闻网-移动互联网与智能搜索领域是未来IT产业发展的趋势!
中国IT产经新闻/智家办公/正文
Managementobjectsearcher用于检索管理信息的入口
来源:
2023-08-19
编辑:晓露

     基于指定的查询检索管理对象的集合。此类是用于检索管理信息的较为常用的入口点之一。例如,它可以用于枚举系统中的所有磁盘驱动器、网络适配器、进程及更多管理对象,或者用于查询所有处于活动状态的网络连接以及暂停的服务等。在实例化之后,此类的实例可以接受在 ObjectQuery 或其派生类中表示的 WMI 查询作为输入,并且还可以选择接受一个 ManagementScope(表示执行查询时所在的 WMI 命名空间)。它还可以接受 EnumerationOptions 中的其他高级选项。当调用此对象的Get()方法时,ManagementObjectSearcher在指定的范围内执行给定的查询,并返回与 ManagementObjectCollection中的查询匹配的管理对象的集合。


      用法步骤:
      1、添加引用:System.Management
      2、引入命名空间:using System.Management;
      3、创建ManagementObjectSearcher对象 anagementObjectSearcher searcher = new ManagementObjectSearcher("select * from " + Key);
      4、通过searcher.Get()获得ManagementObjectCollection集合
      5、遍历ManagementObjectCollection集合获得ManagementObject
      6、通过managementObject[name]或ManagementObject.GetPropertyValue(name)获得想要的属性 。若不知道这里的name该写什么可以遍历打印一下:
      foreach (var property in managementObject.Properties)
{
      Console.WriteLine(property.Name+":"+property.Value);
}

产业点评更多
厂商动态更多
热门综合更多
CopyRight @ 2008-2023 中国IT产经新闻网 All Right Reserved 违者必究 湘ICP备2022017330号-2