Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式检查是否安装了Windows消息传递?_C#_Windows_Messaging - Fatal编程技术网

C# 以编程方式检查是否安装了Windows消息传递?

C# 以编程方式检查是否安装了Windows消息传递?,c#,windows,messaging,C#,Windows,Messaging,是否有一种简单的方法可以使用C#?检测消息传递组件是否已安装以及服务是否在Windows中运行。检查服务的存在及其状态可以通过执行WMI查询来完成: // Setup the query ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_Service WHERE Name = 'Blah'"); //

是否有一种简单的方法可以使用C#?

检测消息传递组件是否已安装以及服务是否在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_服务类的更多信息,请参阅