Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用c停止服务#_C#_Windows_Service - Fatal编程技术网

C# 无法使用c停止服务#

C# 无法使用c停止服务#,c#,windows,service,C#,Windows,Service,我正在尝试暂时停止“程序兼容性助手服务”。但是下面的代码给出了错误“无法在计算机上打开PcaSvc服务”。我使用了“PcaSvc”和“程序兼容性助手服务”作为名称,但它们都给出了相同的错误。服务正在运行。有人能解释一下吗 ServiceController service = new ServiceController("PcaSvc"); try { service.Stop(); service.WaitForStatus(ServiceControllerStatus.St

我正在尝试暂时停止“程序兼容性助手服务”。但是下面的代码给出了错误“无法在计算机上打开PcaSvc服务”。我使用了“PcaSvc”和“程序兼容性助手服务”作为名称,但它们都给出了相同的错误。服务正在运行。有人能解释一下吗

ServiceController service = new ServiceController("PcaSvc");
try
{
    service.Stop();
    service.WaitForStatus(ServiceControllerStatus.Stopped);
}
catch (Exception e)
{
    MessageBox.Show(e.Message);
}

这可能是一个安全问题

见:


另请参见:

你说得对。谢谢