简体   繁体   English

Windows服务状态C ++?

[英]Windows Service Status C++?

How I can get the status of an windows service in C++? 如何在C ++中获取Windows服务的状态?

This is a C# example: 这是一个C#示例:

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++? 但是我如何在C ++中做相同的操作呢?

You need to call OpenSCManager() , then OpenService() and then QueryServiceStatus() to get the status. 您需要调用OpenSCManager() ,然后调用OpenService() ,然后QueryServiceStatus()以获取状态。

When you're done call CloseServiceHandle() twice, once on the service handle, and then on the handle returned by OpenSCManager() . 完成后,调用CloseServiceHandle()两次,一次在服务句柄上,然后在OpenSCManager()返回的句柄上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM