2010-06-16 36 views
6

由於VLC conflict我必須在啓動應用程序時關閉Windows高級文本服務。有沒有特別的API?它是否適用於具有默認權限的用戶?應用程序啓動時禁用Windows服務

+3

禁用不屬於您自己的服務並不真正禮貌;也許用戶需要運行這個服務。您至少應該在某處通知用戶(幫助屏幕,自述文件等)。 – Luke 2010-06-16 14:25:12

回答

2
ServiceController _ServiceController = new ServiceController([NameService]); 
if (!_ServiceController.ServiceHandle.IsInvalid) 
{ 
    _ServiceController.Stop(); 
    _ServiceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(uConstante.CtTempoEsperaRespostaServico)); 
} 
+0

對於正確的代碼:'_ServiceController.ServiceHandle!= null'被替換爲'!_ServiceController.ServiceHandle.IsInvalid && _ServiceController.Status!= ServiceControllerStatus.Stopped' – 2017-01-18 16:37:17

0

只需執行「net stop service-name」停止服務或「net start service-name」啓動服務。 在控制檯(cmd.exe)中鍵入「net start」以列出所有服務。

您需要管理員權限才能啓用/禁用服務。

21

問題標題爲「禁用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"); 
+2

+1這是實際回答問題的唯一答案 – BradleyDotNET 2014-02-26 20:25:33

相關問題