Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Windows service manager from stopping a service c#

I have a custom windows service with my own register handler, how can I prevent it from stopping when it receives the stop command from the services manager ? I established a pipe communication between the service and a GUI and I want to stop it only from the GUI, when I send the windows service the message "stop" not when I try to stop it from windows service manager. I am working in C#

like image 565
AlexandruC Avatar asked Jun 20 '12 17:06

AlexandruC


1 Answers

Does this answer your question?

http://bytes.com/topic/c-sharp/answers/444965-prevent-service-stopping

Set the CanStop property to false. Then you will need an application that the user can use to request a stop. This app would then communicate with your service (via remoting, perhaps) and if the condition is permitted, stop itself. You should be able to do this by dynamically setting 'CanStop' to true, then connecting to yourself with the ServiceController class and issuing the 'Stop' command.

like image 60
Gene S Avatar answered Sep 22 '22 01:09

Gene S