Windows服务状态C++?

Rhi*_*ino 4 c++ windows service status

如何在C++中获取Windows服务的状态?

这是一个C#示例:

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

但是我如何在C++中做相同的操作呢?

Dav*_*nan 7

您需要先打电话OpenSCManager()然后OpenService()QueryServiceStatus()获取状态.

当你完成CloseServiceHandle()两次调用,一次在服务句柄上,然后在返回的句柄上OpenSCManager().