错误 5:启动 Windows 服务时拒绝访问 [英] Error 5 : Access Denied when starting windows service

查看:29
本文介绍了错误 5:启动 Windows 服务时拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试启动我在 C# 中创建的 Windows 服务时遇到此错误:

I'm getting this error when I try to start a windows service I've created in C#:

到目前为止我的代码:

private ServiceHost host = null;

public RightAccessHost()
{
    InitializeComponent();
}

protected override void OnStart(string[] args)
{
    host = new ServiceHost(typeof(RightAccessWcf));
    host.Open();
}

protected override void OnStop()
{
    if (host != null)
        host.Close();
    host = null;
}

更新 #1

我通过向帐户NETWORK SERVICE授予权限解决了上述问题,但现在我遇到了另一个问题:

Update #1

I solved the issue above by granting permissions to the account NETWORK SERVICE but now I have an another problem:

服务无法启动.System.InvalidOperationException:服务RightAccessManagementWcf.RightAccessWcf"的应用程序(非基础设施)端点为零.这可能是因为找不到您的应用程序的配置文件,或者因为在配置文件中找不到与服务名称匹配的服务元素,或者因为没有在服务元素中定义端点.在 System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription description)在 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)在 System.ServiceModel.ServiceHostBase.InitializeRuntime()在 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)在 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)在 RightAccessHosting.RightAccessHost.OnStart(String[] args) 在 C:Users....

Service cannot be started. System.InvalidOperationException: Service 'RightAccessManagementWcf.RightAccessWcf' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element. at System.ServiceModel.Description.DispatcherBuilder.EnsureThereAreNonMexEndpoints(ServiceDescription description) at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) at System.ServiceModel.ServiceHostBase.InitializeRuntime() at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) at RightAccessHosting.RightAccessHost.OnStart(String[] args) in C:Users....

推荐答案

我意识到这篇文章很旧,但没有明显的解决方案,我只是想说说我是如何解决这个问题的.

I realize this post is old, but there's no marked solution and I just wanted to throw in how I resolved this.

第一个 Error 5: Access Denied 错误已通过将输出目录的权限授予 NETWORK SERVICE 帐户解决.

The first Error 5: Access Denied error was resolved by giving permissions to the output directory to the NETWORK SERVICE account.

第二个 Started and then stopped 错误似乎是服务出现故障时的通用消息.检查事件查看器(特别是Windows 日志 > 应用程序")以获取真正的错误消息.

The second Started and then stopped error seems to be a generic message when something faulted the service. Check the Event Viewer (specifically the 'Windows Logs > Application') for the real error message.

就我而言,这是 app.config 中错误的服务配置设置.

In my case, it was a bad service configuration setting in app.config.

这篇关于错误 5:启动 Windows 服务时拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆