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());
}

Comments

Popular posts from this blog

Parse XML to dynamic object in C#

C# Crop white space from around the image