SC_LOCK LockServiceDatabase(hSCManager) | |||
SC_HANDLE hSCManager; |
The LockServiceDatabase function locks a specified database.
hSCManager
Handle obtained from a previous OpenSCManager call which specifies the database to lock.
Returns a lock to 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 | The specified handle was not opened with SC_MANAGER_LOCK access. | |
ERROR_INVALID_HANDLE | The specified handle is invalid. | |
ERROR_SERVICE_DATABASE_LOCKED | The database is locked. |
This function acquires a lock on the database that was opened from a previous OpenSCManager call. There can only be one lock outstanding on a database for a given time.
This lock is a protocol used by setup/configuration programs and the Service Control Manager to serialize access to the service tree in the registry. Setup/configuration programs are expected to acquire the lock before calling Service Control Manager APIs to reconfigure any service.
The only time the Service Control Manager acquires a lock is when it is starting a service. It needs to hold a lock on the active database so that reconfiguration cannot take place when a service is being started.
The lock protocol cannot be strictly enforced by the Service Control Manager because setup/configuration programs may also use registry APIs to reconfigure a service.
This function returns a lock strcture. The lock is held until a subsequent call to UnlockServiceDatabase with this lock structure. If the process which is holding a lock terminates, the Service Control Manager automatically cleans up and releases the lock.