Search code examples
windowssalt-projectservicecontroller

Windows service controller: view `sc failure` settings for a service


I would like to view the current settings of sc failure for a service. Is this possible?

Background:

I'm setting up state configuration for services using Saltstack. Right now, when a service is set up, a command line is run to set the failure behaviour like:

sc failure serviceName reset= 30 actions= restart/5000

I would like to be able to query the current values of the arguments passed to sc failure, so that Salt can verify if any changes need to be made, and log the change in values when pushing out a new configuration.

From the documentation for sc failure and sc query, I don't see anything to support this.

In the registry, at HKLM:\SYSTEM\CurrentControlSet\services\myService\, there is a key FailureActions. But I don't know how to read the value of this key to compare it to my desired state:

PS C:\Users\blaffoy> (Get-ItemProperty -path $key -name failureactions).failureactions
30
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
20
0
0
0
1
0
0
0
136
19
0
0

A little bit of experimentation indicates that the first number corresponds to the reset parameter, but beyond that I don't know how to reconcile the rest of the output.


Solution

  • sc.exe is a command-line interface to the Windows service API. QueryServiceConfig2 handles several query types, which are exposed as the following commands:

    • qdescription
    • qfailure
    • qfailureflag
    • qsidtype
    • qprivs
    • qtriggerinfo

    The command that you need is sc [server] qfailure <service name> <bufferSize>.