由於VLC conflict我必須在啓動應用程序時關閉Windows高級文本服務。有沒有特別的API?它是否適用於具有默認權限的用戶?應用程序啓動時禁用Windows服務
回答
ServiceController _ServiceController = new ServiceController([NameService]);
if (!_ServiceController.ServiceHandle.IsInvalid)
{
_ServiceController.Stop();
_ServiceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(uConstante.CtTempoEsperaRespostaServico));
}
對於正確的代碼:'_ServiceController.ServiceHandle!= null'被替換爲'!_ServiceController.ServiceHandle.IsInvalid && _ServiceController.Status!= ServiceControllerStatus.Stopped' – 2017-01-18 16:37:17
可以使用ServiceController
類此。鏈接的文檔頁面中有代碼示例。
只需執行「net stop service-name」停止服務或「net start service-name」啓動服務。 在控制檯(cmd.exe)中鍵入「net start」以列出所有服務。
您需要管理員權限才能啓用/禁用服務。
問題標題爲「禁用Windows服務...」,但答案都告訴如何停止服務。
大多數的你會發現在谷歌是你可以更新註冊表,使用這樣的事情禁用服務:
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\[YourServiceName]", true);
key.SetValue("Start", 4);
我還沒有嘗試過這種方法,但它看起來好像它會工作。我還想出了一種使用sc.exe來禁用服務的另一種方法:
Process sc = Process.Start("sc.exe", "config [YourServiceName] start= disabled");
+1這是實際回答問題的唯一答案 – BradleyDotNET 2014-02-26 20:25:33
- 1. 從Windows服務啓動應用程序
- 2. Azure應用服務 - 啓動時彈出啓動應用程序
- 3. C#Windows服務COM異常80080005啓動應用程序時
- 4. 在啓動時啓動服務並從服務啓動應用程序?
- 5. 啓動一個禁用的Windows服務?
- 6. 應用程序啓動時自動啓動Android服務
- 7. 從Windows服務啓動Windows Forms應用程序
- 8. 用服務啓動應用程序
- 9. 如何在應用程序啓動時啓動Android服務?
- 10. 如何在Android應用程序啓動時啓動服務?
- 11. 在應用程序啓動時明確啓動GCM服務Android
- 12. 在應用程序啓動時停止已啓動的服務
- 13. 啓動Apache服務器時啓動應用程序
- 14. 啓動時啓動服務和應用程序安裝後
- 15. 如何在新應用程序啓動時啓動服務?
- 16. 啓動後啓動服務時,應用程序崩潰
- 17. 啓動GPS應用程序即服務
- 18. 無應用程序啓動服務
- 19. 從服務啓動應用程序
- 20. Android啓動服務/應用程序
- 21. 運行應用程序時服務未啓動 - 如何顯式啓動服務?
- 22. 在Windows啓動時啓動應用程序啓動
- 23. 從Windows服務啓動GUI應用程序
- 24. 新的Windows服務應用程序版本不會啓動
- 25. 從Windows服務啓動winform應用程序
- 26. Windows服務如何以標準間隔啓動應用程序?
- 27. 在同一應用程序中啓動兩個Windows服務
- 28. 從Windows服務啓動開放式應用程序
- 29. 從Windows服務啓動WinForms應用程序
- 30. 如何從asp.net web應用程序啓動多個windows服務?
禁用不屬於您自己的服務並不真正禮貌;也許用戶需要運行這個服務。您至少應該在某處通知用戶(幫助屏幕,自述文件等)。 – Luke 2010-06-16 14:25:12