Get the disabled status of a Windows Service

房东的猫 提交于 2019-12-20 02:56:36

问题


I have written a windows service and has set its startup type to be 'Automatic'. But after installing the service a user can change its type to 'disabled'.

Is there a way by which I can identify the status of this service after service installation? Can I prevent a user from changing the startup type so that it will always be 'Automatic'?

Thanks


回答1:


There is no API for doing this, but you can check the service start mode in the registry, at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ServiceName\Start. That value will be either 2 (automatic), 3 (manual), or 4 (disabled).




回答2:


You can't really prevent the user from disabling it, except with operating system permissions, unless you're going to be the only admin for the box, you're not going to have that kind of control.

You can use a 3rd-party monitoring tool such as Nagios to monitor services across all your servers, and alert you when they stop running. This has other benefits as it also allows you to monitor many other things, such as MSMQ queue lengths, disk space and memory usage (in fact anything in the performance counters).




回答3:


see ServiceController.Status Property



来源:https://stackoverflow.com/questions/1939611/get-the-disabled-status-of-a-windows-service

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