.net Windows 服务:错误 5:拒绝访问
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3615367/
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
Windows Service : error 5 :Access Denied
提问by TCM
I am trying to create a simple Windows Service. The User Account for the service is NetworkService. Then I ran installUtilfrom command prompt and I got this :
我正在尝试创建一个简单的 Windows 服务。该服务的用户帐户是NetworkService。然后我installUtil从命令提示符运行,我得到了这个:
The Commit phase completed successfully.
The transacted install has completed.
提交阶段成功完成。
事务安装已完成。
which means the service got installed successfully. But when I try to run it from the Service appleti get this error :
这意味着该服务已成功安装。但是当我尝试从它运行它时,Service applet我收到此错误:
Windows cannot the CustomersService service on Local Computer. Error 5 : Access is denied.
Windows cannot the CustomersService service on Local Computer. Error 5 : Access is denied.
I am using 64bit Windows 7.
我正在使用 64 位 Windows 7。
回答by Vaibhav Singh
I am not sure if you've already got this resolved though, the following helped me fix this on my system:
我不确定你是否已经解决了这个问题,以下帮助我在我的系统上解决了这个问题:
- Grant full permissions to the service registry key under
HKLM > System > Current Control Set > Services > <Service Name>. (Grant full permissions to Network Service Built in account on the key) - Check the image path (apparently the output path of the exe under the
bin > Debug. - Add and give full permissions to the Network Service account here too.
- 授予对 下的服务注册表项的完全权限
HKLM > System > Current Control Set > Services > <Service Name>。(授予对密钥上的网络服务内置帐户的完全权限) - 检查图像路径(显然是 .exe 文件下 exe 的输出路径)
bin > Debug。 - 在此处也添加并授予网络服务帐户的完全权限。
This should help!
这应该有帮助!
回答by Mike de Klerk
I got an access denied error 5 when I tried to run a service under "LOCAL SERVICE" user, but under "LOCAL SYSTEM" the service did start. To run the service under "LOCAL SERVICE" I had to do the following:
当我尝试在“LOCAL SERVICE”用户下运行服务时出现访问被拒绝错误 5,但在“LOCAL SYSTEM”下该服务确实启动了。要在“本地服务”下运行服务,我必须执行以下操作:
- Service set to run under "LOCAL SERVICE"
- I gave permissions to the user "LOCAL SERVICE" for the folder where the executable of the service is located in. (Right mouse button om folder, properties, security, add user "LOCAL SERVICE" with as many rights as possible
- Start service now
- 服务设置为在“本地服务”下运行
- 我向用户“LOCAL SERVICE”授予了服务可执行文件所在文件夹的权限。(鼠标右键om文件夹,属性,安全性,添加用户“LOCAL SERVICE”并拥有尽可能多的权限
- 立即开始服务
You can use procmon.exe of SysInternals to monitor the ACCESS DENIED error. Filter on "File System Activity" for the process "services.exe". You will probably see the path of the executable of the service that needs to be started in the "Path" column when the error "Access Denied" error code 5 occures.
您可以使用 SysInternals 的 procmon.exe 来监控 ACCESS DENIED 错误。过滤进程“services.exe”的“文件系统活动”。当出现错误“拒绝访问”错误代码5时,您可能会在“路径”列中看到需要启动的服务的可执行文件的路径。
回答by Alexander Zaldostanov
This worked for me
这对我有用
Go to the service in the service manager >> right click on that service and choose Properties >> Click the Log On tab >> choose the Local System account.
转到服务管理器中的服务 >> 右键单击该服务并选择属性 >> 单击登录选项卡 >> 选择本地系统帐户。
Then start the service.
然后启动服务。
回答by ajay_whiz
Through which user account type are you trying to start/stop the service? Make sure the user has sufficient privileges to start/stop a service.
您尝试通过哪种用户帐户类型启动/停止服务?确保用户有足够的权限来启动/停止服务。

