开发者

How to detect automatic NT service will start

开发者 https://www.devze.com 2023-03-04 15:55 出处:网络
I\'m working on a simple NT service with an application that will monitor it and display status in the task tray. On starting the monitor checks if the service is running and prompts to start it if it

I'm working on a simple NT service with an application that will monitor it and display status in the task tray. On starting the monitor checks if the service is running and prompts to start it if it's not. This is fine until a reboot when the monitor starts before the service and prompts to start it even though 开发者_运维百科it will auto-start.

From reading the docs I thought that the status would be reported as SERVICE_START_PENDING which is the first thing the service does when entering the service main function, however it seems that the status is reported as SERVICE_STOPPED if the SCM has not begun starting the service. Is there any way to detect that the service will begin starting sometime soon?

Thanks, J


I don't think there's any way to predict what the service control manager will do in the future. However, I can think of a couple of things that could mitigate your situation:

  • Monitor the state of the service periodically, and when it goes to "starting", update your icon status appropriately

  • Check the autostart setting of the process, and if it's set to automatic, and your monitor program has only just started then delay reporting that the service is not running (under the assumption that it will probably start soon).


You probably want both QueryServiceConfig and QueryServiceConfig2(). The second call is needed to get the SERVICE_CONFIG_DELAYED_AUTO_START_INFO data.

0

精彩评论

暂无评论...
验证码 换一张
取 消