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)
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)