Wednesday, 18 March 2009

Start/Stop windows service from C#

using System.ServiceProcess;
public void Test()
{
  ServiceController controller = new ServiceController();
  controller.MachineName = ".";
  controller.ServiceName = "MyService";
  
  controller.Stop();            
  //wait until stopped
  controller.Start();
  //wait until started
  controller.Refresh();   
  Console.WriteLine(controller.Status.ToString());
}

No comments:

Post a Comment