2010-04-13 76 views

回答

1

检查服务,其状态的存在,可以通过执行WMI查询来完成:

// Setup the query 
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", 
        "SELECT * FROM Win32_Service WHERE Name = 'Blah'"); 

// Execute the query and enumerate the objects 
foreach (ManagementObject queryObj in searcher.Get()) 
{ 
    // examine the query results to find the info you need. For example: 
    string name = (string)queryObj["Name"]; 
    bool started = (bool)queryObj["Started"]; 
    string status = (string)queryObj["Status"]; 
} 

有关WMI Win32_Service类的详细信息,请参阅here.

相关问题