Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ServiceControlManager returns Error = 5 when Openservice Called

Status
Not open for further replies.

TheMillionDollarMan

Programmer
Jun 10, 2002
132
US
Hi

I have created an application that is to be run as a service. When I try to create the service the ServiceControlManager returns Error = 5 when OpenSCManager is called.

This works on my machine no problem. However on another machine i get this error. How can I solve this problem.

Thanks

 
Try to test the return value against standard error codes for OpenSCManager (ERROR_ACCESS_DENIED,ERROR_DATABASE_DOES_NOT_EXIST, ERROR_INVALID_PARAMETER) and see which one of the above is returned.

Also, you can use GetLastError in conjunction with FormatMessage to get a brief description of the error.
 

Thanks B00gyeMan!
I found out that this is an "Access Denied" type error.

Do you know how I can give myself rights to enable acces to OpenSCManager?

I want to be able to create a service on a target machine.

Thanks
 
Only an administrator or power user cand give itself security rights.

It is not necessary a problem of security. Some application might have locked the database using LockServiceDatabase API. According to MSDN: "The LockServiceDatabase function requests ownership of the service control manager database lock. Only one process can own the lock at any given time."

If you are connecting to a remote database (that is, on a remote machine), you should be aware that "Only authenticated users are granted the SC_MANAGER_CONNECT, SC_MANAGER_ENUMERATE_SERVICE, and SC_MANAGER_QUERY_LOCK_STATUS access rights."

Also, only processes with Administrator privileges are able to open a database handle that can be used by the CreateService and LockServiceDatabase functions.

So, check if you are connecting as an authenticated user and also check your security rights.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top