Platform SDK: Registry

RegQueryInfoKey

The RegQueryInfoKey function retrieves information about the specified registry key.

LONG RegQueryInfoKey(
  HKEY hKey,                      // handle to key
  LPTSTR lpClass,                 // class buffer
  LPDWORD lpcClass,               // size of class buffer
  LPDWORD lpReserved,             // reserved
  LPDWORD lpcSubKeys,             // number of subkeys
  LPDWORD lpcMaxSubKeyLen,        // longest subkey name
  LPDWORD lpcMaxClassLen,         // longest class string
  LPDWORD lpcValues,              // number of value entries
  LPDWORD lpcMaxValueNameLen,     // longest value name
  LPDWORD lpcMaxValueLen,         // longest value data
  LPDWORD lpcbSecurityDescriptor, // descriptor length
  PFILETIME lpftLastWriteTime     // last write time
);

Parameters

hKey
[in] Handle to a currently open key or any of the following predefined reserved handle values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
Windows NT/2000:
HKEY_PERFORMANCE_DATA
Windows 95/98: HKEY_DYN_DATA

lpClass
[out] Pointer to a buffer that receives the null-terminated class string of the key. No classes are currently defined; applications should ignore this parameter. This parameter can be NULL.
lpcClass
[in/out] Pointer to a variable that specifies the size, in TCHARs, of the buffer pointed to by the lpClass parameter. This size should include the terminating null character. When the function returns, this variable contains the length of the class string stored in the buffer. The count returned does not include the terminating null character. If the buffer is not big enough, the function returns ERROR_MORE_DATA, and the variable contains the size of the string, in characters, without counting the null character.

If lpClass is NULL, lpcClass can be NULL.

Windows NT/2000: If the lpClass parameter is a valid address, but the lpcClass parameter is not (for example, it is NULL), the function returns ERROR_INVALID_PARAMETER.

Windows 95: If the lpClass parameter is a valid address, but the lpcClass parameter is not (for example, it is NULL), the function returns ERROR_SUCCESS instead of ERROR_INVALID_PARAMETER. To ensure compatibility with other platforms, verify that lpcClass is valid before calling the function.

lpReserved
Reserved; must be NULL.
lpcSubKeys
[out] Pointer to a variable that receives the number of subkeys contained by the specified key. This parameter can be NULL.
lpcMaxSubKeyLen
[out] Pointer to a variable that receives the length, in TCHARs, of the key's subkey with the longest name. This parameter can be NULL.

Windows NT/2000: The length does not include the terminating null character.

Windows 95/98: The length includes the terminating null character.

lpcMaxClassLen
[out] Pointer to a variable that receives the length, in TCHARs, of the longest string specifying a subkey class. The count returned does not include the terminating null character. This parameter can be NULL.
lpcValues
[out] Pointer to a variable that receives the number of values associated with the key. This parameter can be NULL.
lpcMaxValueNameLen
[out] Pointer to a variable that receives the length, in TCHARs, of the key's longest value name. The length does not include the terminating null character. This parameter can be NULL.
lpcMaxValueLen
[out] Pointer to a variable that receives the length, in bytes, of the longest data component among the key's values. This parameter can be NULL.
lpcbSecurityDescriptor
[out] Pointer to a variable that receives the length, in bytes, of the key's security descriptor. This parameter can be NULL.
lpftLastWriteTime
[out] Pointer to a FILETIME structure that receives the last write time. This parameter can be NULL.

Windows NT/2000: The function sets the members of the FILETIME structure to indicate the last time that the key or any of its value entries was modified.

Windows 95: The function sets the members of the FILETIME structure to zero. This is because the system does not keep track of registry key last write time information.

Return Values

If the function succeeds, the return value is ERROR_SUCCESS.

If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.

Remarks

The key identified by the hKey parameter must have been opened with KEY_QUERY_VALUE access (KEY_READ access includes KEY_QUERY_VALUE access).

Windows 95/98: No registry subkey or value name may exceed 255 characters.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winreg.h; include Windows.h.
  Library: Use Advapi32.lib.
  Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000.

See Also

Registry Overview, Registry Functions, FILETIME, RegDeleteKey, RegEnumKey, RegEnumKeyEx, RegEnumValue, RegQueryValue, RegQueryValueEx