2013-08-23 40 views

回答

4

這樣做的選擇都不是簡單的,他們需要調用一些方法把它關閉。你可以使用類似下面的擴展名,http://www.codeproject.com/Articles/6164/A-ServiceInstaller-Extension-That-Enables-Recovery或使用命令滾動你自己的東西。

[DllImport("advapi32.dll", EntryPoint="ChangeServiceConfig2")] 
public static extern bool 
ChangeServiceFailureActions(IntPtr hService, int dwInfoLevel, 
[ MarshalAs(UnmanagedType.Struct) ] ref SERVICE_FAILURE_ACTIONS lpInfo); 


[DllImport("advapi32.dll", EntryPoint="ChangeServiceConfig2")] 
public static extern bool 
ChangeServiceDescription(IntPtr hService, int dwInfoLevel, 
[ MarshalAs(UnmanagedType.Struct) ] ref SERVICE_DESCRIPTION lpInfo); 

http://netcode.ru/dotnet/?lang=&katID=30&skatID=277&artID=7660以獲取更多信息

+0

啊,這似乎是更正確的方法來做到這一點。 – Alexandru

2

您可以使用sc.exe從命令行設置恢復選項。這個答案對如何做到這一點使用C#一個很好的例子:

Install Windows Service with Recovery action to Restart

+0

難道沒有更好,更內置的方式? – Alexandru

+0

不是我所知道的。 –

+0

爲了記錄,我這樣做了。上述方法是調用它的更好方法,但讀者代碼的目的不明確。我認爲這是實現這個目標的最明確的方法。 – Alexandru

相關問題