开发者

Windows Service Status C++?

开发者 https://www.devze.com 2023-02-20 11:47 出处:网络
How I can get the status of an windows service in C++? This is a C# example: ServiceController sc = new ServiceController(\"Spooler\", \"Server1\");

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.Runnin开发者_开发问答g)
{
    MessageBox.Show("The service is running.");
}

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


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().

0

精彩评论

暂无评论...
验证码 换一张
取 消