views:

3806

answers:

4

When I try to start a service I created in Visual Studio I receive the following error:

System error 5 has occurred.

Access is denied.

I am running the command line with elevated privileges, so it's not that problem. Is there any place I can look to see what error is occuring.

+10  A: 

To get it to work I needed to add permissions to the output bin\debug folder for my service project.

The Local Service account didn't have permissions to the output .exe file, and this was why the error was occuring.

Daniel O
Silly thing really. I simply ran the install from the debug folder which I thought would place the actual executable in the proper directory. The permissions did the trick.
Jeff.Crossett
Worked for me too - thanks. I just wanted to try it out and installing from a Debug folder was the lazy option :-)
rohancragg
It's a good thing that you posted this answer when you found the solution yourself. I had the same problem and it helped me. Thanks :-D
Dariusz Walczak
You saved my life....
Ankit Rathod
+2  A: 

I see you've fixed the problem; but in reality, you shouldn't normally be running the service from a project's bin folder anyway - the files should be put somewhere project and profile independent (for example, under program files). For debugging purposes (when it will be in the bin folder), you can detect whether it is a service in Main(), and if it is being run interactively just run the service code directly, rather than the usual service-start setup.

You can detect either by adding a command line argument, or you can try checking Environment.UserInteractive.

Marc Gravell
Yea, in my scenario is was in DEV, and a post-build event deploys and starts the service for me, ready for me to attach to it.
Daniel O
A: 

I had the same problem because my project and its source code was in a folder that had NTFS's Encrypting File System (EFS) enabled. This caused by compiled assemblies being encrypted aswell and the user running my service didn't have permissions to decrypt them. Removing EFS was the easy solution for this. It can be done by command line using CIPHER.EXE, which is a Windows tool.

exton
A: 

Thanks for the help Daniel O, your own answer helped me :-)