How to disable the Windows service if it is turned off. manage it from webapplication

I want to disable the windows service when it is off. Is it possible to do through code from a web application using C #? I am using asp.net mvc and c #.

+5
source share
4 answers

You are looking for the ServiceController class.

+7
source

It can be done, but it is unlikely that you want to run your website under an account that has sufficient rights to be able to start / stop services. You can use the ServiceController class to start the service; see here.

+6
source

Here is an example:

  var sc = new ServiceController("Your service name"); sc.Stop(); sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(120)); logger.Info("service stopped."); 
+2
source

Use the ServiceController class.

+1
source

All Articles