用 C# 启动服务 [英] Start Service with C #
问题描述
我正在尝试使用 C# 启动服务,但出现以下错误:
ServiceController service = new ServiceController(sServiceName);service.MachineName = localComputerName;服务.开始();service.WaitForStatus(ServiceControllerStatus.Running);
<块引用>
System.InvalidOperationException:无法在计算机上打开服务System.ComponentModel.Win32Exception:访问被拒绝System.ServiceProcess.ServiceController.GetServiceHandle(Int32requiredAccess) 在 System.ServiceProcess.ServiceController.Stop()
查找您的权限.请问您需要从管理员帐户运行您的应用程序(或 Visual Studio).
I'm trying to start a service with C # but throws me the following error:
ServiceController service = new ServiceController(sServiceName);
service.MachineName = localComputerName;
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
System.InvalidOperationException: Cannot open service on computer System.ComponentModel.Win32Exception: Access is denied at System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) at System.ServiceProcess.ServiceController.Stop()
Look for your permissions. May me you need to run your app (or Visual Studio) from Administrator account.
这篇关于用 C# 启动服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!