2

关于可以在此处看到的服务的恢复选项卡属性:

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

是否有获取以下属性值的 API:

  1. 例如值的第一次失败:“不采取任何行动”
  2. 第二次失败
  3. 随后的失败
  4. 重置失败计数

我更喜欢在 PowerShell 中这样做,但也想了解其他选项。

4

3 回答 3

1

我不熟悉 PowerShell,但有一个 Win32 API 可用:QueryServiceConfig2()。将dwInfoLevel参数设置为SERVICE_CONFIG_FAILURE_ACTIONS,并在参数中传递一个指向缓冲区的指针,该缓冲区lpBuffer足够大以接收SERVICE_FAILURE_ACTIONS结构。

于 2013-10-29T21:31:29.583 回答
0

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.

于 2013-10-23T13:22:28.507 回答
0

例如,您可以使用 cs.exe 控制它

Get-Service -DisplayName YourService | % { sc.exe failure $_.Name actions= /0 reset= 0 }
于 2015-06-08T07:35:51.767 回答