title: Error 5 : Access Denied when starting windows service
body: <p>I'm getting this error when I try to start a windows service I've created in C#:</p>
  
  <p><img src="https://i.stack.imgur.com/53rgc.png" alt="alt text"></p>
  
  <p>My Code so far:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <h2>Update #1</h2>
  
  <p>I solved the issue above by granting permissions to the account <em>NETWORK SERVICE</em> but now I have an another problem:</p>
  
  <p><img src="https://i.stack.imgur.com/Fp6Zq.png" alt="alt text"></p>
  
  <h2>Update #2</h2>
  
  <blockquote>
    <p>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....</p>
  </blockquote>