2010-04-13 94 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.

相關問題