//Retreive the Service and Machine name from config file
string servicename = ConfigurationManager.AppSettings["ServiceMachine"].ToString();
string serviceMachine = ConfigurationManager.AppSettings["MachineName"].ToString();
//Create a new ServiceController object with the service and machine name as parameters
ServiceController svc = new ServiceController(servicename, serviceMachine);
//Start the service if its not already running
if (svc.Status == ServiceControllerStatus.Stopped)
{
//Start the Service
svc.Start();
}
|