# Function Reference

# _WinAPI_RegCloseKey

Closes a handle to the specified registry key

#include <WinAPIReg.au3>
_WinAPI_RegCloseKey ( $hKey [, $bFlush = False] )

## Parameters

$hKey | Handle to the open key to be closed. The handle must have been opened by the _WinAPI_RegCreateKey() or _WinAPI_RegOpenKey() function.
$bFlush | [optional] Specifies whether writes all the attributes of the specified registry key into the registry, valid values: True - Write changes to disk before close the handle. False - Don't write (Default).

## Return Value

Success: | 1.
Failure: | 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

## Related

_WinAPI_RegCreateKey, _WinAPI_RegOpenKey

## See Also

Search RegCloseKey in MSDN Library.

## Example

### Example 1

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

    _DebugSetup(Default, True)

    Example()

    Func Example()
        Local $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, 'SOFTWARE\AutoIt v3\AutoIt', $KEY_QUERY_VALUE)
        If @error Then
            _DebugReport("! RegOpenKey @error =" & @error & @CRLF & @TAB & _WinAPI_GetErrorMessage(@extended) & @CRLF)
            Exit
        EndIf

        Local $tFT = _WinAPI_RegQueryLastWriteTime($hKey)
        $tFT = _Date_Time_FileTimeToLocalFileTime($tFT)
        Local $tST = _Date_Time_FileTimeToSystemTime($tFT)
        _WinAPI_RegCloseKey($hKey)

        _DebugReport('! Last modified at: ' & _WinAPI_GetDateFormat(0, $tST) & ' ' & _WinAPI_GetTimeFormat(0, $tST) & @CRLF)

    EndFunc   ;==>Example

### Example First parameter being the full Key string

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

    _DebugSetup(Default, True)

    Example()

    Func Example()
        Local $hKey = _WinAPI_RegOpenKey('HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt', '', $KEY_QUERY_VALUE)
        If @error Then
            _DebugReport("! RegOpenKey @error =" & @error & @TAB & _WinAPI_GetErrorMessage(@extended) & @CRLF)
            Exit
        EndIf

        Local $tFT = _WinAPI_RegQueryLastWriteTime($hKey)
        $tFT = _Date_Time_FileTimeToLocalFileTime($tFT)
        Local $tST = _Date_Time_FileTimeToSystemTime($tFT)
        _WinAPI_RegCloseKey($hKey)

        _DebugReport('!Last modified at: ' & _WinAPI_GetDateFormat(0, $tST) & ' ' & _WinAPI_GetTimeFormat(0, $tST) & @CRLF)

    EndFunc   ;==>Example

### Example 3 Running in X64 Mode (should be run under Full SciTE4AutoIt)

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

    _DebugSetup(Default, True)

    Example()

    Func Example()
        Local $hKey = _WinAPI_RegOpenKey($HKEY_LOCAL_MACHINE, 'SOFTWARE\AutoIt v3\AutoIt', $KEY_QUERY_VALUE)
        If @error Then
            _DebugReport("! RegOpenKey @error = " & @error & @CRLF & @TAB & _WinAPI_GetErrorMessage(@extended) & @CRLF)
            Exit
        EndIf

        Local $tFT = _WinAPI_RegQueryLastWriteTime($hKey)
        $tFT = _Date_Time_FileTimeToLocalFileTime($tFT)
        Local $tST = _Date_Time_FileTimeToSystemTime($tFT)
        _WinAPI_RegCloseKey($hKey)

        _DebugReport('- Last modified at: ' & _WinAPI_GetDateFormat(0, $tST) & ' ' & _WinAPI_GetTimeFormat(0, $tST) & @CRLF)

    EndFunc   ;==>Example