Checking if a service is up

  • Thread starter Thread starter r
  • Start date Start date
R

r

Hi,
I would like to check from within my c# app,
if certain services are up or down, to activate and to stop
them.
Any idea on how to do it?
Thanks in advance
 
Hello,
You can manipulate existing windows services using ServiceController
class in System.ServiceProcess namespace. You can create the service
controller with the following line of code:

System.ServiceProcess.ServiceController controller = new
System.ServiceProcess.ServiceController("ServiceNameGoesHere");

you can check about the service state through
System.ServiceProcess.ServiceControllerStatus.

if(controller.Status ==
System.ServiceProcess.ServiceControllerStatus.Running)
controller.Stop();

Please see MSDN for further details on Manipulating Windows services.

HTH. Cheers.
Maqsood Ahmed [MCP C#,SQL Server]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Back
Top