I have a service which will fail when certain resources are unavailable. I have configured it to try restarting twice, then send me an SMS on the third attempt. Unfortunately windows only gives you the option to reset the failure count after a certain number of days, whereas I really want it to reset on every third failure. The problem is that once the service is running again, one more failure will cause it to send another SMS and not even try to restart the service.
So I want to include in my SMS script some code to reset the failure counter. I have found the following registry location:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\
Which contains among other things (binary) settings for failure actions, but no counter as far as I can tell.
The sc
command lets you query all sorts of stuff, but also doesn't return a failure count.
Ideally I'd like a way to query/reset the failure counter programatically, but a commandline or registry solution would be fine (since I can script them).
The count is reset to 0 if the service has not failed for dwResetPeriod seconds. Calling ChangeServiceConfig2 with the dwResetPeriod of SERVICE_FAILURE_ACTIONS set to 0 will reset the count.
The service control manager counts the number of times each service has failed since the system booted. The count is reset to 0 if the service has not failed for dwResetPeriod seconds.
Calling ChangeServiceConfig2 with the dwResetPeriod of SERVICE_FAILURE_ACTIONS set to 0 will reset the count. You will need to query (see QueryServiceConfig2) the original setting of dwResetPeriod, set it to zero then reset it back to the original to preserve the state.
Reset fail count after setting is amount of time from service start after which fail counter will be reseted. According to defined sample configurations where each service close unexpectedly after 5s from start each case never hits reset counter definition. To reset counter timeout should be less then 5s ex.
The Win32 API allows you to specify the failure count be reset after X number of seconds, not X number of days. Look at the dwResetPeriod members of the SERVICE_FAILURE_ACTIONS structure.
A for the failure counter itself, that is maintained privately inside of the SCM, which knows how many times a given service has failed since Windows was booted. That counter is not accessible for applications to reset manually, or even to query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With