Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 5 : Access Denied when starting windows service

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

alt text

My Code so far:

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; } 

Update #1

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

alt text

Update #2

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....

like image 952
Kris-I Avatar asked Nov 24 '10 13:11

Kris-I


People also ask

Can't start a service error 5 access is denied?

This typically occurs due to insufficient permissions on the system. Therefore, many people can fix Error 5: Access is denied error by simply trying to run the command or launch an installer with administrator's rights.


1 Answers

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

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

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.

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

like image 118
Justin Skiles Avatar answered Sep 20 '22 20:09

Justin Skiles