ZwQueryValueKey function

The ZwQueryValueKey routine returns a value entry for a registry key.

Syntax

NTSTATUS ZwQueryValueKey(
  _In_      HANDLE                      KeyHandle,
  _In_      PUNICODE_STRING             ValueName,
  _In_      KEY_VALUE_INFORMATION_CLASS KeyValueInformationClass,
  _Out_opt_ PVOID                       KeyValueInformation,
  _In_      ULONG                       Length,
  _Out_     PULONG                      ResultLength
);

Parameters

KeyHandle

Handle to the key to read value entries from. This handle is created by a successful call to ZwCreateKey or ZwOpenKey.

ValueName

Pointer to the name of the value entry to obtain data for.

KeyValueInformationClass

A KEY_VALUE_INFORMATION_CLASS value that determines the type of information returned in the KeyValueInformation buffer.

KeyValueInformation

Pointer to a caller-allocated buffer that receives the requested information.

Length

Specifies the size, in bytes, of the KeyValueInformation buffer.

ResultLength

Pointer to a variable that receives the size, in bytes, of the key information. If the ZwQueryValueKey routine returns STATUS_SUCCESS, callers can use the value of this variable to determine the amount of data returned. If the routine returns STATUS_BUFFER_OVERFLOW or STATUS_BUFFER_TOO_SMALL, callers can use the value of this variable to determine the size of buffer required to hold the key information.

Return Value

ZwQueryValueKey returns STATUS_SUCCESS on success, or the appropriate error code on failure. Possible error code values include:

STATUS_OBJECT_NAME_NOT_FOUND
The registry value was not available.
STATUS_BUFFER_OVERFLOW
The buffer supplied is too small, and only partial data has been written to the buffer. *ResultLength is set to the minimum size required to hold the requested information.
STATUS_BUFFER_TOO_SMALL
The buffer supplied is too small, and no data has been written to the buffer. *ResultLength is set to the minimum size required to hold the requested information.
STATUS_INVALID_PARAMETER
The KeyInformationClass parameter is not a valid KEY_VALUE_INFORMATION_CLASS value.

Remarks

The KeyHandle passed to ZwQueryValueKey must have been opened with KEY_QUERY_VALUE access. This is accomplished by passing KEY_QUERY_VALUE, KEY_READ, or KEY_ALL_ACCESS as the DesiredAccess parameter to ZwCreateKey or ZwOpenKey.

For more information about working with registry keys, see Using the Registry in a Driver.

For calls from kernel-mode drivers, the NtXxx and ZwXxx versions of a Windows Native System Services routine can behave differently in the way that they handle and interpret input parameters. For more information about the relationship between the NtXxx and ZwXxx versions of a routine, see Using Nt and Zw Versions of the Native System Services Routines.

Requirements

   
Windows Driver kit version
Target platform Universal
Minimum KMDF version
Minimum UMDF version
Header wdm.h (include Wdm.h, Ntddk.h, Ntifs.h)
Library
IRQL PASSIVE_LEVEL
DDI compliance rules IrqlZwPassive, PowerIrpDDis, ZwRegistryCreate, ZwRegistryOpen, HwStorPortProhibitedDDIs, ZwRegistryCreate(storport), ZwRegistryOpen(storport)

See Also

KEY_VALUE_BASIC_INFORMATION
KEY_VALUE_FULL_INFORMATION
KEY_VALUE_INFORMATION_CLASS
KEY_VALUE_PARTIAL_INFORMATION
Using Nt and Zw Versions of the Native System Services Routines
ZwCreateKey
ZwEnumerateValueKey
ZwOpenKey

Send comments about this topic to Microsoft