Function Reference


_WinAPI_RegQueryValue

Retrieves the type and data for the specified value name associated with an open registry key

#include <WinAPIReg.au3>
_WinAPI_RegQueryValue ( $hKey, $sValueName, ByRef $tValueData )

Parameters

$hKey Handle to an open registry key. The key must have been opened with the KEY_QUERY_VALUE 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_PERFORMANCE_NLSTEXT
    $HKEY_PERFORMANCE_TEXT
    $HKEY_USERS
$sValueName The name of the registry value.
If $sValueName is empty string, the function retrieves the type and data for the key's unnamed or default value, if any.
$tValueData The structure (buffer) that receives the value data. This structure must be created before function call.

Return Value

Success: The size of the data copied to $tValueData, in bytes, @extended flag will contain the code that indicates the data type ($REG_*).
Failure: 0 and sets the @error flag to non-zero, @extended flag may contain the system error code.

Remarks

If the data has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, returned size includes any terminating null character or characters unless the data was stored without them.

If the buffer specified by $tValueData parameter is not large enough to hold the data, the function returns $REG_ERROR_MORE_DATA (234) and returns the required buffer size.
In this case, the contents of the buffer are undefined.

Related

_WinAPI_RegCreateKey, _WinAPI_RegOpenKey

See Also

Search RegQueryValueEx in MSDN Library.

Example

Example 1

#include <APIRegConstants.au3>
#include <Debug.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIError.au3>
#include <WinAPIReg.au3>

;~ #AutoIt3Wrapper_UseX64=Y

_DebugSetup(Default, True)

Example()

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

        Local $tData = DllStructCreate('wchar[260]')
        _WinAPI_RegQueryValue($hKey, 'InstallDir', $tData)
        _WinAPI_RegCloseKey($hKey)

        _DebugReport("- Install Dir = " & DllStructGetData($tData, 1) & @CRLF)

EndFunc   ;==>Example

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

#AutoIt3Wrapper_UseX64=Y

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

_DebugSetup(Default, True)

Example()

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

        Local $tData = DllStructCreate('wchar[260]')
        _WinAPI_RegQueryValue($hKey, 'InstallDir', $tData)
        _WinAPI_RegCloseKey($hKey)

        _DebugReport(DllStructGetData($tData, 1) & @CRLF)

EndFunc   ;==>Example