c++ - On Non-Admin Account OpenSCManager() function returns null -


Please help me shortly I am writing a code to run a service, it works fine on the administrator account Does, but the non-admin user account, OpenSCManager () function returns empty. Please let me know how to allow non-admin user accounts to start and stop services. Or do I need to do something else? Please answer shortly

Perhaps you specify OpenSCManager by The SC_MANAGER_ALL_ACCESS flag, which actually requires a set of privileges, is provided by default to the administrator only by default. Here you can only send SC_MANAGER_CONNECT to start / stop services here. The flag needs to be specified, which is provided by default for any certified user The expertise.

Now that you have a handle for the service manager, you must use the OpenService to get a handle for the service for the right to start / stop the service. You must specify GENERIC_READ | GENERIC_EXECUTE as the desired access (in fact I think that you can only reduce the necessary rights for SERVICE_START and SERVICE_STOP and, if necessary, Then SERVICE_INTERROGATE ).

Here is the problem: General Services DACL does not provide such rights to normal users, so you must change the service's DACL to require service Allow to stop / stop; See . For more information about the right to access services, see.

If, instead of the same service, you want to allow any service to start / stop any service, I do not know that it is possible without changing all the DACL, but my In opinion this is definitely a bad idea.

Note that even in the case of a single service, if the service is a privileged account (such as LocalSystem ) or if it is an important system service, then unrecognized users False with it, it's still a bad idea. You should start / stop the system from users, which are not necessary for the system.

Curiously, why do you need users to start / stop service?


Comments