Error 5 : Access Denied when starting windows service

Solution 1:

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.

Solution 2:

Computer -> Manage -> Service -> [your service] properties. Then the the tab with the account information. Play with those settings, like run the service with administrator account or so.

That did it for me.

EDIT: What also can be the problem is that, most services are run as LOCAL SERVICE or LOCAL SYSTEM accounts. Now when you run C:/my-admin-dir/service.exe with those accounts but they are not allowed to execute anything in that directory, you will get error 5. So locate the executable of the service, RMB the directory -> Properties -> Security and make sure that the account the service is run with, is in the list of users that are alloewd to have full control over the directory.

Solution 3:

This worked for me.

  1. Right-click on top-level folder containing the service executable. Go to Properties
  2. Go to "Security" Tab
  3. Click "EDIT"
  4. Click "ADD"
  5. Enter the name "SYSTEM", click OK
  6. Highlight SYSTEM user, and click ALLOW check-box next to "Full control"
  7. Click OK twice

Solution 4:

I also got the same error , It resolved by Right click on Service > Properties >Log On > log on as : Local System Account.

Solution 5:

Make sure the Path to executable points to an actual executable (Right click service -> Properties -> General tab). Via powershell (and sc.exe) you can install a service without pointing it to an actual executable... ahem.