JavaSa
JavaSa

Reputation: 6241

How to get win32_service recovery tab properties

Regarding service's recovery tab properties that can be seen here:

http%253A%252F%252Fwww.ehloworld.com%252Fwp-content%252Fuploads%252F2011%252F10%252Fservice-recovery-options-1.png

Is there an API to get the following property values:

  1. First failure for example value: "Take no action"
  2. Second failure
  3. Subsequent failures
  4. Reset fail count

I prefer a way to do so in PowerShell but would like to know about other options as well.

Upvotes: 2

Views: 1604

Answers (3)

e.tichy
e.tichy

Reputation: 11

You can control it for instance with cs.exe

Get-Service -DisplayName YourService | % { sc.exe failure $_.Name actions= /0 reset= 0 }

Upvotes: 0

Remy Lebeau
Remy Lebeau

Reputation: 595782

I am not familiar with PowerShell, but there is a Win32 API available: QueryServiceConfig2(). Set the dwInfoLevel parameter to SERVICE_CONFIG_FAILURE_ACTIONS, and pass a pointer to a buffer in the lpBuffer parameter that is large enough to receive a SERVICE_FAILURE_ACTIONS struct.

Upvotes: 1

MDMoore313
MDMoore313

Reputation: 3311

One needs to modify the services reg key, under

HKLM\System\CurrentControlSet\services\<service name>\

Adding a value of type binary with the name FailureActions. I don't know how it's structured you'd have to play around with that, but as it relates to powershell it would simply be grabbing to real name of the service (maybe using get-service if all you have is the display name), and navigating to that regkey and creating a new value, for example:

PS C:\Users\*\Desktop> $ByteArray = 0,0,0,144,10,23,253,33                                                                                                               
PS C:\Users\*\Desktop> Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\services\AdobeARMservice -Name FailureActions -Type Binary -Value $ByteArray -Force         
PS C:\Users\*\Desktop> Get-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\services\AdobeARMservice -Name FailureActions                                               


FailureActions : {0, 0, 0, 144...}                                                                                                                                           
PSPath         : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\AdobeARMservice                                                    
PSParentPath   : Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services                                                                    
PSChildName    : AdobeARMservice                                                                                                                                             
PSDrive        : HKLM                                                                                                                                                        
PSProvider     : Microsoft.PowerShell.Core\Registry                                                                                                                          

Adding a byte[ ], but like I mentioned you'd have to either reverse engineer the meaning of the array, or just copy an existing one or something similar.

Upvotes: 0

Related Questions