windows could not start the service on local computer error 5 access is denied

i got code for a service from this website:
http://code.msdn.microsoft.com/windowsdesktop/CppWindowsService-cacf4948

but when i try to start the service in SCM i get the error:
windows could not start the service on local computer error 5 access is denied


my user account is set to administrative and i tried other things websites suggested but it still won't work

please help!
Run CppWindowsService.exe -install from an elevated command prompt.
i ran the cmd as administrator. it installs fine the problem is when i try start the service in the SCM
Last edited on
SCM must also run as administrator to start a service. Or call ServiceStart() API directly from your install function inside your application.
how do i run the SCM as administrator?
please help i really want to get this service working

Last edited on
i tried adding requireAdministrator to the service controller application's manifest but this didn't work either. can someone please help with this?
No changes are required to the application. Just compile it in release mode statically and start the service from SCM, it works for me (if you are administrator on your machine).

So recompile everything , restart your computer and it will work.
compiling it in release mode didn't help either.
and i am defiantly part of the administration group so i don't know why its not working
i even tried running the exe file in the default admin account and the same error message came up.

so the problem must be in the code?
@modoran did you download this service and run it on your computer?
Last edited on
Yes. I compiled the sample using VS2010 SP1.
so the problem must be with my computer not the code then?
my user account is set admin so i don't know how to fix this
i am using vs2008
in the program the code to set the account is #define SERVICE_ACCOUNT L"NT AUTHORITY\\LocalService"

i found that using the LocalService account doesn't work.
It will only work if i set it to my user account but this service will also be used on other computers and i don't want to change the account properties every time (that's why using LocalService would be good if i can get it to work)
Setting the pszAccount and pszPassword variables in the call to the CreateService function (under ServiceInstaller.cpp) to "NULL" will assume that the service is to be run under the Local System account which should be just as good for most purposes.
Last edited on
i had the project folder saved on my desktop so using LocalService as the account, it wasn't able to find the project
but moving the folder to C: drive solved it
Topic archived. No new replies allowed.