2011-03-26 106 views
3

我如何获得C++中的Windows服务的状态?Windows服务状态C++?

这是一个C#示例:

ServiceController sc = new ServiceController("Spooler", "Server1"); 
if (sc.Status == ServiceControllerStatus.Running) 
{ 
    MessageBox.Show("The service is running."); 
} 

但我怎么做C++中的相同呢?

回答

6

您需要致电OpenSCManager(),然后OpenService(),然后QueryServiceStatus()以获得状态。

当你完成呼叫CloseServiceHandle()两次,一旦在服务处理,然后在由OpenSCManager()返回的句柄。

+0

但我必须包括什么? – Rhino 2011-03-26 12:29:04

+1

@Rhino每个Win32函数的MSDN文档都会告诉你,对于每个函数,你需要使用哪些包含文件。请阅读“需求”一节中的页面。 – 2011-03-26 12:29:51