RegEnumKey

  LONG RegEnumKey(hkey, iSubKey, lpszName, cchName)    
  HKEY hkey; /* handle of key to query */
  DWORD iSubKey; /* index of subkey to query */
  LPTSTR lpszName; /* address of buffer for subkey name */
  DWORD cchName; /* size of subkey buffer */

The RegEnumKey function enumerates the subkeys of a specified open configuration registry key. It does this by copying the name of an indexed subkey of the specified key. The function enumerates one subkey each time it is invoked.

Parameters

hkey

Identifies a currently open key or any of the following predefined reserved handle values:

HKEY_CLASSES_ROOT HKEY_CURRENT_USER HKEY_LOCAL_MACHINE HKEY_USERS

The keys returned are relative to the key specified by hkey.

iSubKey

Specifies the index of the subkey to retrieve. This value should be zero for the first call to the RegEnumKey function, and should be incremented for subsequent calls.

lpszName

Points to a buffer that receives the name of the subkey. This function copies only the name of the subkey, not the full key hierarchy, to the buffer.

cchName

Specifies the size of the buffer at lpszName (in characters). To determine the required buffer size, use the RegQueryInfoKey function to determine the size of the largest subkey for hkey. The maximum required buffer size is MAX_PATH characters.

Return Value

The return value is ERROR_SUCCESS if the function is successful. Otherwise, it is an error value.

Comments

To enumerate subkeys, an application should initially call the RegEnumKey function with the iSubKey parameter set to zero. The application should then increment the iSubKey parameter and call the RegEnumKey function until there are no more subkeys (the function returns ERROR_CANT_READ).

While an application is using the RegEnumKey function it should not make calls to any registration functions that might change the key being queried.

The key specified by hkey must have been opened with KEY_ENUMERATE_SUB_KEYS access. Use the RegCreateKeyEx or RegOpenKeyEx function to open the key.

The RegEnumKey function may be used as either a wide-character function (where text arguments must use Unicode) or an ANSI function (where text arguments must use characters from the Windows 3.x character set installed).

See Also

RegCloseKey, RegCreateKeyEx, RegEnumKeyEx, RegOpenKeyEx, RegQueryValue