Prevent Windows service manager from stopping a service c#

☆樱花仙子☆ 提交于 2019-11-29 21:51:11

问题


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#


回答1:


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.




回答2:


As an alternative you could simply secure the service settings (modify the service DACL) such that only a special user account (and perhaps SYSTEM) has the rights to stop the service and install this special local user account during installation.

Your control application can then use the standard Service Control Manager functions with this special user's security token and everything will work as expected without having to do anything unusual.



来源:https://stackoverflow.com/questions/11125158/prevent-windows-service-manager-from-stopping-a-service-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!