SC_HANDLE OpenSCManager(lpMachineName, lpDatabaseName, dwDesiredAccess) | |||
LPTSTR lpMachineName; | |||
LPTSTR lpDatabaseName; | |||
DWORD dwDesiredAccess; |
The OpenSCManager function establishes a connection to Service Control Manager and opens the database.
lpMachineName
Name of the target machine; NULL or empty string connects to the local Service Control Manager.
lpDatabaseName
Name of the database maintained by the Service Control Manager to open. If NULL is specified, the active database is opened by default.
This parameter can be one of the following predefined names:
Name | Meaning |
ServicesActive | ||
the active database which the system is booted on. | ||
ServicesFailed | ||
the database that previously failed to boot. |
dwDesiredAccess
The access types desired to access the Service Control Manager. These access types will be checked against the Discretionary Access Control list of the SCManager object to determine whether the accesses are granted or denied. The access type of SC_MANAGER_CONNECT is implicitly specified by calling this function.
Returns a handle to the Service Control Manager database. If return value is NULL, an error has occurred. Use GetLastError to determine the cause of the failure.
Errors | Value | Meaning |
ERROR_ACCESS_DENIED | Specified desired access was denied. | |
ERROR_DATABASE_DOES_NOT_EXIST | Database specified to open does not exist. | |
ERROR_INVALID_PARAMETER | A parameter specified is invalid. |
This function establishes a connection to the Service Control Manager on the specified machine, and opens the specified database. The caller must have SC_MANAGER_CONNECT access to the SCManager object being connected to.
The handle returned is for future calls to the Service Control Manager. This handle can be closed by calling CloseServiceHandle.
If the “ServicesFailed” database is opened via this function, there are some restrictions imposed on the returned handle. The handle cannot be used to call OpenService with any one of the following desired access:
SERVICE_START
SERVICE_STOP
SERVICE_PAUSE_CONTINUE
SERVICE_INTERROGATE
The Service Control Manager only allows services in the “ServicesFailed” database to be reconfigured. Services can only be started from the “ ServicesActive” database.