Working with Windows Services in C Sharp
From RiceFamily Wiki
Revision as of 18:42, 12 April 2015 by Rice0009 (Talk | contribs) (Rice0009 moved page Working with Windows Services in C to Working with Windows Services in C Sharp)
- Taken from : http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running
- http://adamprescott.net/2012/08/03/check-the-status-of-a-windows-service-in-c/
- https://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontroller.aspx
using System.ServiceProcess;
ServiceController sc = new ServiceController(SERVICENAME);
switch (sc.Status) {
- case ServiceControllerStatus.Running:
- return "Running";
- case ServiceControllerStatus.Stopped:
- return "Stopped";
- case ServiceControllerStatus.Paused:
- return "Paused";
- case ServiceControllerStatus.StopPending:
- return "Stopping";
- case ServiceControllerStatus.StartPending:
- return "Starting";
- default:
- return "Status Changing";
}