Skip to content

Latest commit

 

History

History
161 lines (115 loc) · 5.24 KB

nf-winsvc-lockservicedatabase.md

File metadata and controls

161 lines (115 loc) · 5.24 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winsvc.LockServiceDatabase
LockServiceDatabase function (winsvc.h)
Requests ownership of the service control manager (SCM) database lock. Only one process can own the lock at any specified time.
LockServiceDatabase
LockServiceDatabase function
_win32_lockservicedatabase
base.lockservicedatabase
winsvc/LockServiceDatabase
base\lockservicedatabase.htm
security
87861465-c966-479a-b906-27ae36cc83c8
12/05/2018
LockServiceDatabase, LockServiceDatabase function, _win32_lockservicedatabase, base.lockservicedatabase, winsvc/LockServiceDatabase
winsvc.h
Windows.h
Windows
Windows XP [desktop apps only]
Windows Server 2003 [desktop apps only]
Advapi32.lib
Advapi32.dll
Windows
19H1
LockServiceDatabase
winsvc/LockServiceDatabase
c++
APIRef
kbSyntax
DllExport
Advapi32.dll
LockServiceDatabase

LockServiceDatabase function

-description

[As of Windows Vista, this function is provided for application compatibility and has no effect on the database.]

Requests ownership of the service control manager (SCM) database lock. Only one process can own the lock at any specified time.

-parameters

-param hSCManager [in]

A handle to the SCM database. This handle is returned by the OpenSCManager function, and must have the SC_MANAGER_LOCK access right. For more information, see Service Security and Access Rights.

-returns

If the function succeeds, the return value is a lock to the specified SCM database.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

The following error codes can be set by the SCM. Other error codes can be set by registry functions that are called by the SCM.

Return code Description
ERROR_ACCESS_DENIED
The handle does not have the SC_MANAGER_LOCK access right.
ERROR_INVALID_HANDLE
The specified handle is not valid.
ERROR_SERVICE_DATABASE_LOCKED
The database is locked.

-remarks

A lock is a protocol used by setup and configuration programs and the SCM to serialize access to the service tree in the registry. The only time the SCM requests ownership of the lock is when it is starting a service.

A program that acquires the SCM database lock and fails to release it prevents the SCM from starting other services. Because of the severity of this issue, processes are no longer allowed to lock the database. For compatibility with older applications, the LockServiceDatabase function returns a lock but has no other effect.

Windows Server 2003 and Windows XP:  Acquiring the SCM database lock prevents the SCM from starting a service until the lock is released. For example, a program that must configure several related services before any of them starts could call LockServiceDatabase before configuring the first service. Alternatively, it could ensure that none of the services are started until the configuration has been completed.

A call to the StartService function to start a service in a locked database fails. No other SCM functions are affected by a lock.

The lock is held until the SC_LOCK handle is specified in a subsequent call to the UnlockServiceDatabase function. If a process that owns a lock terminates, the SCM automatically cleans up and releases ownership of the lock.

Failing to release the lock can cause system problems. A process that acquires the lock should release it as soon as possible.

-see-also

ChangeServiceConfig

OpenSCManager

QueryServiceLockStatus

Service Configuration

Service Functions

SetServiceObjectSecurity

StartService

UnlockServiceDatabase