Starting and stopping a Windows Serivce application programmatical

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everybody,

Is it possible to start and stop a windows service
programatically, i.e. by code?


thanks alot guys.
 
Avi,
Yes, see the online help for System.ServiceProcess.ServiceController.

http://msdn.microsoft.com/library/d...serviceprocessservicecontrollerclasstopic.asp

http://msdn.microsoft.com/library/d...vbcon/html/vboriMonitoringWindowsServices.asp

Specifically the Stop, Start, and WaitForStatus methods along with the
CanStop property.

For example I use code similiar to the following to "Restart" a service:

controller.Stop()
controller.WaitForStatus(ServiceControllerStatus.Stopped)
controller.Start()

Hope this helps
Jay
 
Back
Top