用C#启动服务
我正在尝试使用 C# 启动服务,但出现以下错误:
ServiceController service = new ServiceController(sServiceName);
service.MachineName = localComputerName;
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
System.InvalidOperationException:无法在计算机上打开服务 System.ComponentModel.Win32Exception:访问被拒绝 System.ServiceProcess.ServiceController.GetServiceHandle(Int32 desiredAccess) 在 System.ServiceProcess.ServiceController.Stop()
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您是否已将异常文本红色化?您根本没有启动服务器的权限。阅读:http://msdn.microsoft.com/en-us/library/h846e9b3 .aspx (http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontrollerpermission.aspx 特别)或以管理员身份启动应用程序
Have you red the exception text? you simply have no permission to start a server. Read: http://msdn.microsoft.com/en-us/library/h846e9b3.aspx ( http://msdn.microsoft.com/en-us/library/system.serviceprocess.servicecontrollerpermission.aspx specifically) or simply launch the application as an administrator
您可能需要查看此问题,以获取有关启动服务时权限的一些帮助。
You may want to check out this question for some help on permissions when starting your service.
寻找您的权限。请问您需要从管理员帐户运行您的应用程序(或 Visual Studio)。
Look for your permissions. May me you need to run your app (or Visual Studio) from Administrator account.
您的
访问被拒绝
错误向我表明您的进程/应用程序正在运行的身份没有启动和启动的权限。停止服务。Your
Access is denied
error indicates to me that the identity under which your process / application is running does not have permission to start & stop services.