# Function Reference

# _WinAPI_RegEnumKey

Enumerates the subkeys of the specified open registry key

#include <WinAPIReg.au3>
_WinAPI_RegEnumKey ( $hKey, $iIndex )

## Parameters

$hKey | Handle to an open registry key. The key must have been opened with the $KEY_ENUMERATE_SUB_KEYS access right. This handle is returned by the _WinAPI_RegCreateKey() or _WinAPI_RegOpenKey() function. It can also be one of the following predefined keys: $HKEY_CLASSES_ROOT $HKEY_CURRENT_CONFIG $HKEY_CURRENT_USER $HKEY_LOCAL_MACHINE $HKEY_PERFORMANCE_DATA $HKEY_USERS
$iIndex | The index of the subkey to retrieve. This parameter should be zero for the first call to the _WinAPI_RegEnumKey() function and then incremented for subsequent calls.

## Return Value

Success: | The string that contains the name of the subkey. The LastWriteTime of the subkey is return in @extended.
Failure: | Sets the @error flag to non-zero, @extended flag may contain the system error code.

## Remarks

To enumerate subkeys, an application should initially call the _WinAPI_RegEnumKey() function with the $iIndex parameter set to zero.
The application should then increment the $iIndex parameter and call _WinAPI_RegEnumKey() until there are no more subkeys (meaning the @extended flag sets to ERROR_NO_MORE_ITEMS (259)).
The application can also set $iIndex to the index of the last subkey on the first call to the function and decrement the index until the subkey with the index 0 is enumerated.
To retrieve the index of the last subkey, use the _WinAPI_RegQueryInfoKey() function.
While an application is using the _WinAPI_RegEnumKey() function,
it should not make calls to any registration functions that might change the key being enumerated.

## Related

_WinAPI_RegCreateKey, _WinAPI_RegOpenKey, _WinAPI_RegQueryInfoKey

## See Also

Search RegEnumKeyEx in MSDN Library.

## Example

    #include <Date.au3>
    #include <Debug.au3>
    #include <WinAPIError.au3>
    #include <WinAPIReg.au3>

    Example()

    Func Example()
        Local $hKey = _WinAPI_RegOpenKey($HKEY_CLASSES_ROOT, 'CLSID', $KEY_READ)
        If @error Then
            _DebugSetup(Default, True)
            _DebugReport("! RegOpenKey @error =" & @error & @CRLF & @TAB & _WinAPI_GetErrorMessage(@extended))
            Exit
        EndIf
        Local $iCount = _WinAPI_RegQueryInfoKey($hKey)
        Local $aKey[$iCount[0]][2], $tLocalFILETIME, $tFileWriteTime
        For $i = 0 To UBound($aKey) - 1
            $aKey[$i][0] = _WinAPI_RegEnumKey($hKey, $i)
            $tFileWriteTime = @extended
            If $tFileWriteTime Then
                $tLocalFILETIME = _Date_Time_FileTimeToLocalFileTime($tFileWriteTime)
                $aKey[$i][1] = _Date_Time_FileTimeToStr($tLocalFILETIME, 1)
            EndIf
        Next

        _WinAPI_RegCloseKey($hKey)

        _DebugArrayDisplay($aKey, '_WinAPI_RegEnumKey')

    EndFunc   ;==>Example