Windows Service Status C++?

2020-02-12 13:19发布

How I can get the status of an windows service in C++?

This is a C# example:

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

But how do I do the equivalent in C++?

1条回答
该账号已被封号
2楼-- · 2020-02-12 13:50

You need to call OpenSCManager(), then OpenService() and then QueryServiceStatus() to get the status.

When you're done call CloseServiceHandle() twice, once on the service handle, and then on the handle returned by OpenSCManager().

查看更多
登录 后发表回答