在应用程序启动时禁用Windows服务

Sib*_*Guy 6 .net c# windows vlc

由于VLC冲突,我必须在我的应用程序启动时关闭Windows高级文本服务.那有什么特殊的API吗?它是否适用于具有默认权限的用户?

xr2*_*0xr 27

问题标题为"禁用Windows服务...",但答案都告诉我们如何停止服务.

您在Google上可以找到的大多数内容是您可以使用以下内容更新注册表以禁用服务:

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\[YourServiceName]", true);
key.SetValue("Start", 4);
Run Code Online (Sandbox Code Playgroud)

我没有尝试过这种方法,但似乎它会起作用.我还想出了一个使用sc.exe来禁用该服务的不同方法:

Process sc = Process.Start("sc.exe", "config [YourServiceName] start= disabled");
Run Code Online (Sandbox Code Playgroud)

  • +1这是实际回答问题的唯一答案 (4认同)

Pau*_*que 2

ServiceController _ServiceController = new ServiceController([NameService]);
if (!_ServiceController.ServiceHandle.IsInvalid) 
{
     _ServiceController.Stop();
     _ServiceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(uConstante.CtTempoEsperaRespostaServico));
}
Run Code Online (Sandbox Code Playgroud)