Enumerates the subkeys of the specified open registry key. The function retrieves the name of one subkey each time it is called.
Note This function is provided only for compatibility with 16-bit versions of Windows. Applications should use the RegEnumKeyEx function.
LONG WINAPI RegEnumKey( _In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPTSTR lpName, _In_ DWORD cchName );
- hKey [in]
A handle to an open registry key. The key must have been opened with the KEY_ENUMERATE_SUB_KEYS access right. For more information, see Registry Key Security and Access Rights.
- dwIndex [in]
The index of the subkey of hKey to be retrieved. This value should be zero for the first call to the RegEnumKey function and then incremented for subsequent calls.
Because subkeys are not ordered, any new subkey will have an arbitrary index. This means that the function may return subkeys in any order.
- lpName [out]
A pointer to a buffer that receives the name of the subkey, including the terminating null character. This function copies only the name of the subkey, not the full key hierarchy, to the buffer.
For more information, see Registry Element Size Limits.
- cchName [in]
The size of the buffer pointed to by the lpName parameter, in TCHARs. To determine the required buffer size, use the RegQueryInfoKey function to determine the size of the largest subkey for the key identified by the hKey parameter.
If the function succeeds, the return value is ERROR_SUCCESS.
If the function fails, the return value is a system error code. If there are no more subkeys available, the function returns ERROR_NO_MORE_ITEMS.
If the lpName buffer is too small to receive the name of the key, the function returns ERROR_MORE_DATA.
To enumerate subkeys, an application should initially call the RegEnumKey function with the dwIndex parameter set to zero. The application should then increment the dwIndex parameter and call the RegEnumKey function until there are no more subkeys (meaning the function returns ERROR_NO_MORE_ITEMS).
The application can also set dwIndex to the index of the last key on the first call to the function and decrement the index until the subkey with index 0 is enumerated. To retrieve the index of the last subkey, use the RegQueryInfoKey.
While an application is using the RegEnumKey function, it should not make calls to any registration functions that might change the key being queried.
Minimum supported client
|Windows 2000 Professional [desktop apps only]|
Minimum supported server
|Windows 2000 Server [desktop apps only]|
Unicode and ANSI names
|RegEnumKeyW (Unicode) and RegEnumKeyA (ANSI)|
- Registry Functions
- Registry Overview