Reputation: 39
I want to determine if the service I started is actually started and not in starting status... How can I know if the service is still running after I start it? Maybe get the event that it started or something like that...
using System.ServiceProcess;
ServiceController sc = new ServiceController(SERVICENAME);
sc.start();
Upvotes: 0
Views: 509
Reputation:
try,
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";
}
or you can check,
ServiceController[] services = ServiceController.GetServices();
foreach(ServiceController service in services)
{
Console.WriteLine(service.ServiceName+"=="+ service.Status);
}
Upvotes: 1