GetSharedServiceRegistryStateKey function (winsvc.h)

Returns a handle for a registry key for a service and associated programs to read and/or write state to.

Syntax

DWORD GetSharedServiceRegistryStateKey(
  SC_HANDLE                          ServiceHandle,
  SERVICE_SHARED_REGISTRY_STATE_TYPE StateType,
  DWORD                              AccessMask,
  HKEY                               *ServiceStateKey
);

Parameters

ServiceHandle

StateType

A member of the SERVICE_SHARED_REGISTRY_STATE_TYPE specifying the shared state type for which the service registry key is retrieved.

AccessMask

The access mask with which to attempt to open the state key. For more information, see Registry Key Security and Access Rights.

ServiceStateKey

Receives the output registry key handle.

Return value

ERROR_SUCCESS when all operations complete successfully; otherwise, a Win32 error code.

Remarks

For ServiceSharedRegistryStatePersistent, the security of the directory is set to only provide write access to the local system account, the service SID, and local administrators. Ensure service SIDs are enabled for any service that calls this API. For more information, see SERVICE_SID_INFO.

For a similar API that provides service state exclusively for use by the service itself, see GetServiceRegistryStateKey.

All service state registry keys are deleted by the service control manager once the service is uninstalled.

Requirements

Requirement Value
Minimum supported client Windows 11 (Build 22000)
Minimum supported server Windows Server 2022 (Build 20348)
Header winsvc.h
Library Onecore.lib

See also

OpenService

GetServiceRegistryStateKey

SERVICE_SID_INFO