以编程方式检查Windows Messaging是否已安装?

时间:2010-04-13 14:57:20

标签: c# windows messaging

是否有一种简单的方法可以使用C#检测邮件组件是否已安装且服务是否在Windows中运行?

1 个答案:

答案 0 :(得分: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.