有没有一种简单的方法可以使用 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_Service 类的更多信息,请参阅 here.
关于c# - 以编程方式检查是否安装了 Windows Messaging?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2630580/