开发者

Programmatically Check if Windows Messaging Installed?

Is there an easy way to detect whether the messaging component is installed and the 开发者_运维技巧service is running in Windows using C#?


Checking for the existence of the service, and its status, could be accomplished by executing a WMI query:

// 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"];
}

For more info on the WMI Win32_Service class, see here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜