Draemon
Draemon

Reputation: 34711

How do you get the current failure count for a windows service

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).

Upvotes: 5

Views: 4766

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 595827

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.

Upvotes: 1

Related Questions