Friday, May 08, 2009

Programmatically Start/Stop Windows Service

Source: http://www.dotnetspider.com/resources/865-How-start-stop-windows-services-programmati.aspx

[C#]

using System.ServiceProcess; // add .Net Reference to Project

ServiceController controller = new ServiceController();

controller.MachineName = ".";
controller.ServiceName = "MySQL";
string status = controller.Status.ToString();

// Stop the service
controller.Stop();

// Start the service
controller.Start();

No comments:

Post a Comment