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++?
You need to call
OpenSCManager()
, thenOpenService()
and thenQueryServiceStatus()
to get the status.When you're done call
CloseServiceHandle()
twice, once on the service handle, and then on the handle returned byOpenSCManager()
.