当前位置 : 主页 > 网络编程 > net编程 >

c#使用wmi

来源:互联网 收集:自由互联 发布时间:2023-10-08
using System.Management; ManagementClass mc = new ManagementClass("Win32_Service"); ManagementObjectSearcher sr = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE State='Running'"); /*"Stopped","Start Pending","Stop Pending",
using System.Management;

ManagementClass mc = new ManagementClass("Win32_Service");
ManagementObjectSearcher sr = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE State='Running'");
/*"Stopped","Start Pending","Stop Pending","Running","Continue Pending","Pause Pending","Paused","Unknown"/*

foreach( ManagementObject srv in sr.Get() )
{
Console.Write(srv["DisplayName"].ToString()+ "\n");
}

添加托管类的方法
using WMI.ROOT.CIMV2; //自动生成

ManagementObjectSearcher sr = new ManagementObjectSearcher("SELECT * FROM Win32_Service WHERE State='Running'");
Service s = new Service();

ManagementObjectCollection objs =sr.Get();
Service.ServiceCollection cols = new Service.ServiceCollection(objs);
foreach (Service ss in cols)
{
Console.Write(ss.Caption.ToString() + "\n");
}
上一篇:数字转大写(c#)
下一篇:没有了
网友评论