Difference between revisions of "Working with Windows Services in C Sharp"

From RiceFamily Wiki
Jump to: navigation, search
(Created page with "Taken from : http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running using System.ServiceProcess; ServiceController sc = new ServiceContro...")
 
Line 1: Line 1:
 
Taken from : http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running
 
Taken from : http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running
 
+
-----
 
using System.ServiceProcess;
 
using System.ServiceProcess;
  

Revision as of 18:32, 12 April 2015

Taken from : http://stackoverflow.com/questions/178147/how-can-i-verify-if-a-windows-service-is-running


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";

}