Windows无法在本地计算机上启动[服务名称]服务。错误5:访问被拒绝

时间:2016-07-22 15:28:59

标签: c# visual-studio-2015

我知道很多人会认为这个问题是重复的,之前已经解决了, 但我在这个问题上遇到了麻烦,我现在非常沮丧,因为我无法解决这个问题。

这是我第一次使用Windows服务,我想以编程方式安装我的服务,我想出了这个解决方案:

ServiceProcessInstaller ProcesServiceInstaller = new ServiceProcessInstaller();
ProcesServiceInstaller.Account = ServiceAccount.LocalSystem;
/**
    I already try to used this
    ProcesServiceInstaller.Account = ServiceAccount.LocalService;
    ProcesServiceInstaller.Username = null;
    ProcesServiceInstaller.Password = null;
**/
ServiceInstaller ServiceInstallerObj = new ServiceInstaller();
InstallContext Context = new System.Configuration.Install.InstallContext();
String path = String.Format("/assemblypath={0}", @"" + System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location));
String[] cmdline = { path };

Context = new System.Configuration.Install.InstallContext("Service-Install.log", cmdline);
ServiceInstallerObj.Context = Context;
ServiceInstallerObj.DisplayName = serviceName;
ServiceInstallerObj.Description = "Sample Description";
ServiceInstallerObj.ServiceName = serviceName;
ServiceInstallerObj.StartType = ServiceStartMode.Automatic;
ServiceInstallerObj.Parent = ProcesServiceInstaller;

System.Collections.Specialized.ListDictionary state = new System.Collections.Specialized.ListDictionary();
ServiceInstallerObj.Install(state); 

以上代码正常运行,我可以在Services中看到它。 但每次我右键单击它并尝试启动服务我都会收到此错误:

Windows could not start the [service name] service on Local Computer.
Error 5: Access is Denied.

我搜索解决方案,但这些都不起作用:

首先我用这个配置我的清单:

<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

第二个链接:Link1Link2

通过以下

*Right-click on top-level folder containing the service executable. Go to Properties
*Go to "Security" Tab
*Click "EDIT"
*Click "ADD"
*Enter the name "SYSTEM","NETWORK SERVICE", "SERVICE" click OK (I already add this 3 account)
*Highlight "SYSTEM","NETWORK SERVICE", "SERVICE" user, and click ALLOW check-box next to "Full control"
*Click OK twice

并没有任何效果。

更新

下图是我添加的安全许可。 enter image description here enter image description here

我已经允许所有复选框*(拒绝除外)*特别是完全控制。

以下图像是我在Windows事件查看器中的图像。 enter image description here

,错误是拒绝访问 enter image description here

任何人都可以帮助我吗?谢谢!

0 个答案:

没有答案
相关问题