I\'m getting this error when I try to start a windows service I\'ve created in C#:
My Code
I accidentally set my service to run as Local service
solution was to switch to Local System
If you are getting this error on a server machine try give access to the folder you got the real windows service exe. You should go to the security tab and select the Local Service as user and should give full access. You should do the same for the exe too.
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.
One of the causes for this error is insufficient permissions (Authenticated Users) in your local folder. To give permission for 'Authenticated Users' Open the security tab in properties of your folder, Edit and Add 'Authenticated Users' group and Apply changes.
Once this was done I was able to run services even through network service account (before this I was only able to run with Local system account).
Right click on the service
in service.msc and select property
.
You will see a folder path under Path to executable
like C:\Users\Me\Desktop\project\Tor\Tor\tor.exe
Navigate to C:\Users\Me\Desktop\project\Tor and right click on Tor.
Select property
, security
, edit
and then add
.
In the text field enter LOCAL SERVICE
, click ok and then check the box FULL CONTROL
Click on add
again then enter NETWORK SERVICE
, click ok
, check the box FULL CONTROL
Then click ok (at the bottom)
Use LocalSystem Account instead of LocalService Account in Service Installer.
You can do this either from doing below change in design view of your service installer:
Properties of Service Process Installer -> Set Account to LocalSystem.
or by doing below change in in designer.cs file of your service installer:
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;