How to start Windows services from C# code

  • Thread starter Thread starter nivedita
  • Start date Start date
N

nivedita

I got below function from http://techinterviewquestion.blogspot.com/
blog. it is working fine. i used

public void StartService(string ServiceName)
{
ServiceController sc = new ServiceController(ServiceName);
if (sc != null && sc.Status == ServiceControllerStatus.Stopped)
{

sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running);

}
}
 
Back
Top