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

Tibco Rendezvous (tibrv) C# .Net example

Parse XML to dynamic object in C#