#region StartService //To start Windows Service exe created and installed in Services.msc public bool StartService(string serviceName) { ServiceController sc = new ServiceController(serviceName); try { if ((sc.Status.Equals(ServiceControllerStatus.Running))) { // Check whether the service if the current status is Running. return true; } else { sc.Start(); } } catch { } return false; } #endregion #region StopService //To stop Windows Service exe created and installed in Services.msc public bool StopService(string serviceName) { bool startservice = false; ServiceController sc = new ServiceController(serviceName); try { if ((sc.Status.Equals(ServiceControllerStatus.Stopped))) { // Check whether the service if the current status is Stopped return true; } //Stop the Windows Service installed in services.msc else { sc.Stop(); } } catch { } return false; } #endregion
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)