GetServiceRegistryStateKey function (winsvc.h)

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

Syntax

DWORD GetServiceRegistryStateKey(
  SERVICE_STATUS_HANDLE       ServiceStatusHandle,
  SERVICE_REGISTRY_STATE_TYPE StateType,
  DWORD                       AccessMask,
  HKEY                        *ServiceStateKey
);

Parameters

ServiceStatusHandle

A handle to the status information structure for the current service. This handle is returned by the RegisterServiceCtrlHandler function.

StateType

A member of the SERVICE_REGISTRY_STATE_TYPE specifying the state type for which the service registry key is retreived.

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 ServiceRegistryStatePersistent, the security of the directory is set to only provide write access to the local system account and the service SID. 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 that can be shared with associated programs, see GetSharedServiceRegistryStateKey.

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

Requirements

Requirement Value
Minimum supported client Windows 10, version 2004 (10.0; Build 19041)
Minimum supported server Windows Server, version 2004 (10.0; Build 19041)
Header winsvc.h
Library Onecore.lib

See also

RegisterServiceCtrlHandler

GetSharedServiceRegistryStateKey

SERVICE_SID_INFO