How to get the current crash counter for a Windows service

I have a service that will be unavailable if some resources are unavailable. I configured it to try restarting twice, and then send me an SMS on the third attempt. Unfortunately, only windows give you the ability to reset the failure count after a certain number of days, while I really want to reset it every third failure. The problem is that after the service resumes, another failure will cause it to send another SMS and not even try to restart the service.

So, I want to include some code in my SMS script in the reset counter failure. I found the following registry location:

HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \

Which contains, among other things, (binary) settings for failure actions, but without a counter, as far as I can tell.

The sc command allows you to query all kinds of materials, but also does not return an error counter.

Ideally, I would like to request / reset the failure counter programmatically, but a command line or registry solution would be fine (since I can script them).

+4
source share
2 answers

The Win32 API allows you to specify a reset error counter after X seconds, not X days. Look at the dwResetPeriod elements of the SERVICE_FAILURE_ACTIONS structure.

A for the failure counter itself, which is maintained confidentially inside SCM, which knows how many times this service has failed since Windows started. This counter is not available for applications reset manually or even for a request.

0
source

I am a developer for an open source Windows hosting platform called Daemoniq. Setting service recovery options is one of its functions. You can download it from http://daemoniq.org

Current features include:

  • container agnostic service location through CommonServiceLocator
  • set common service properties such as serviceName, displayName, description and serviceStartMode via app.config
  • run multiple windows services in the same process
  • set recovery options via app.config
  • install services depend on via app.config
  • set credentials for a service process through the command line
  • install, uninstall, debug services through the command line

Thanks!

0
source

All Articles