Platform SDK: DLLs, Processes, and Threads |
Many operations require an open handle to an SCManager object. The following example demonstrates how to obtain the handle.
Different operations on the SCM database require different levels of access, and you should only request the minimum access required. If SC_MANAGER_ALL_ACCESS is requested, the OpenSCManager function fails if the calling process does not have administrator privileges. The following example shows how to request full access to the ServicesActive database on the local machine.
// Open a handle to the SC Manager database. schSCManager = OpenSCManager( NULL, // local machine NULL, // ServicesActive database SC_MANAGER_ALL_ACCESS); // full access rights if (schSCManager == NULL) MyErrorExit("OpenSCManager");