2013-10-23 58 views
2

關於服務的恢復選項卡屬性,可以在這裏看到:如何獲得win32_service時恢復選項卡性能

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

是否有一個API來獲取以下屬性值:

  1. 第一次失敗了示例值:「不採取行動」
  2. 第二次失敗
  3. 後續失敗
  4. 重置失敗計數

我喜歡的方式在PowerShell中這樣做,但想知道其他選擇。

+0

刪除了C#標籤,因爲這問題似乎並未有任何具體關於C#。 – tnw

回答

0

一個需要修改服務REG鍵,下

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

添加binary類型的值名爲FailureActions。我不知道它是如何構建的,你不得不隨意使用它,但是因爲它涉及到powershell,它只會抓住服務的真實名稱(如果你擁有的只是顯示名稱,也許使用get-service),以及導航到註冊表項來,創造一個新的價值,例如:

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                               

添加一個byte [],但就像我提到你不得不逆向工程數組的意義,或者只是複製現有或類似的東西。

1

我不熟悉PowerShell的,但有一個Win32 API的使用:QueryServiceConfig2()。在dwInfoLevel參數設置爲SERVICE_CONFIG_FAILURE_ACTIONS,和一個指針傳遞給在lpBuffer參數足夠大以容納SERVICE_FAILURE_ACTIONS結構的緩衝器。

0

你可以用cs.exe控制它例如

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