windows 服务控制器无法启动服务 - 拒绝访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/490772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:54:10  来源:igfitidea点击:

Service Controller not able to start service - Access denied

windows

提问by kjayakum

I am using a service controller in a win forms application to start and stop a service which listens to a message queue and processes the messages. I get an access denied error when the service is started from the win forms application.I am using Vista Home Basic and an account which is of type administrator and I have used Log As - Local System Account. The service can be started and stopped normally using the Service Management Console but I get an error when I try to Start the service programatically.Can someone provide some guidance as to how to fix this issue.

我在 win 窗体应用程序中使用服务控制器来启动和停止侦听消息队列并处理消息的服务。从 win 表单应用程序启动服务时,我收到访问被拒绝错误。我使用的是 Vista Home Basic 和一个管理员类型的帐户,并且我使用了登录为 - 本地系统帐户。可以使用服务管理控制台正常启动和停止该服务,但是当我尝试以编程方式启动该服务时出现错误。有人可以提供一些有关如何解决此问题的指导。

回答by Zooba

Probably you have elevated when opening the services console, but not for your own app.

可能您在打开服务控制台时已提升,但不是为您自己的应用程序。

Add an "Application Manifest File" (that is the name of the template in Visual Studio) and set the requested execution level to "requireAdministrator" (there are comments in the manifest file that will help).

添加“应用程序清单文件”(即 Visual Studio 中模板的名称)并将请求的执行级别设置为“requireAdministrator”(清单文件中的注释会有所帮助)。