C# 无法在 NetworkService 帐户中启动 Windows 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11978054/
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
Cannot Start Windows Service in NetworkService account
提问by Saher Ahwal
I have a windows service project implementation that I am trying to install as network service.
我有一个 Windows 服务项目实现,我试图将其安装为网络服务。
process = new ServiceProcessInstaller();
process.Account = ServiceAccount.NetworkService;
however whenever I try to start the service I get :
但是,每当我尝试启动服务时,我都会得到:
System error 5 has occurred.
Access is denied.
This comes after running the net start MyServicecommand in the visual studio command prompt which is running as administrator by the way.
这是在net start MyService以管理员身份运行的 Visual Studio 命令提示符中运行命令之后出现的。
Any help on how to get this to work? Thanks.
有关如何使其工作的任何帮助?谢谢。
采纳答案by oleksii
I would check that the Network Service account has permissions to execute. Steps to check:
我会检查网络服务帐户是否具有执行权限。检查步骤:
- In Windows explorer go to the folder containing the binaries of the service
- Right-click on the folder > Properties > Security tab > Edit button
- Add > "NETWORK SERVICE" > OK
- Give it full control (just to test and then reduce permissions till it working)
- 在 Windows 资源管理器中,转到包含服务二进制文件的文件夹
- 右键单击文件夹 > 属性 > 安全选项卡 > 编辑按钮
- 添加>“网络服务”>确定
- 给予它完全控制(只是为了测试然后减少权限直到它工作)


回答by Erik Philips
Your Net Start MyServiceis probably not running with escalated privileges. Your command requires (I believe) Administrative Privileges.
您Net Start MyService可能没有以升级的权限运行。您的命令需要(我相信)管理权限。
Update
更新
Not sure why, but your privileges on your service are weird. By default privileges of services should look like:
不知道为什么,但您对服务的特权很奇怪。默认情况下,服务的权限应如下所示:
D:(A;CI;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;SY)
ACE Type: ACCESS_ALLOWED_ACE_TYPE
Trustee: NT AUTHORITY\SYSTEM
AccessMask:
ADS_RIGHT_DELETE
ADS_RIGHT_READ_CONTROL
ADS_RIGHT_WRITE_DAC
ADS_RIGHT_WRITE_OWNER
ADS_RIGHT_DS_CREATE_CHILD
ADS_RIGHT_DS_DELETE_CHILD
ADS_RIGHT_ACTRL_DS_LIST
ADS_RIGHT_DS_SELF
ADS_RIGHT_DS_READ_PROP
ADS_RIGHT_DS_WRITE_PROP
ADS_RIGHT_DS_DELETE_TREE
ADS_RIGHT_DS_LIST_OBJECT
ADS_RIGHT_DS_CONTROL_ACCESS
However your's looks like:
但是你的看起来像:
D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)
ACE Type: ACCESS_ALLOWED_ACE_TYPE
Trustee: NT AUTHORITY\SYSTEM
AccessMask:
ADS_RIGHT_READ_CONTROL
ADS_RIGHT_DS_CREATE_CHILD
ADS_RIGHT_ACTRL_DS_LIST
ADS_RIGHT_DS_SELF
ADS_RIGHT_DS_READ_PROP
ADS_RIGHT_DS_WRITE_PROP
ADS_RIGHT_DS_DELETE_TREE
ADS_RIGHT_DS_LIST_OBJECT
ADS_RIGHT_DS_CONTROL_ACCESS
I'm not sure exactly how that came to be. Try uninstalling and reinstalling?
我不确定这到底是怎么来的。尝试卸载并重新安装?
You can download SddlParse (google it :) to parse out the Security Descriptor Definition Language.
您可以下载 SddlParse (google it :) 来解析安全描述符定义语言。
回答by CoreTech
The "Access denied" message applies to the user trying to start the service, not the account in which the service is run.
“拒绝访问”消息适用于尝试启动服务的用户,而不是运行服务的帐户。
Can you start the service from:
您可以从以下位置启动服务:
- the Services Control Panel applet?
- an elevated command prompt you started yourself (not from Visual Studio)?
- 服务控制面板小程序?
- 您自己启动的提升的命令提示符(不是从 Visual Studio 启动的)?

