Windows Service Failure Detection

Is it possible for one Windows service to detect if one of the other running Windows services is stopped?

For some reason, third-party services sometimes stop, and I have to manually start them again. I need a service to automate this annoying process.

+3
source share
1 answer

I would strongly advise you to focus your efforts on correcting the problems diagnosed, and not on the fire symptoms. Find out why third party services are stopping / failing and nipping problems in the bud.

, - , ServiceController, , MSDN. , , Start, , .

(, ), .NET, , , # , :

//Add a reference to System.ServiceProcess

using System.ServiceProcess;

var services = ServiceController.GetServices();
foreach (var service in services)
{
    if (service.ServiceName == myServiceName &&
        service.Status == ServiceControllerStatus.Stopped)
    {
        service.Start();
    }
}
+5

All Articles