2
有一種簡單的方法來檢測郵件組件是否安裝和服務是用C#在Windows上運行?以編程方式檢查是否安裝了Windows消息傳遞?
有一種簡單的方法來檢測郵件組件是否安裝和服務是用C#在Windows上運行?以編程方式檢查是否安裝了Windows消息傳遞?
檢查服務,其狀態的存在,可以通過執行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.