Previous Topic: RegQueryValue - Retrieve a Text StringNext Topic: RegSetValue - Associate the Registry Key with a Text String


RegQueryVariable - Retrieve the Type and Value of a Variable

Valid on Windows

The RegQueryVariable function retrieves the type and value of the specified variable for the specified registry key.

Function format:

Format 1

RegQueryVariable(hKey as Integer, name as String, strvalue as String, intvalue as Integer) as Integer
hKey

Identifies a currently open key or a predefined key. The hKey parameter can have one of the following predefined values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
name

Identifies the name of the requested variable.

strvalue

Identifies the output parameter that is to hold the string value of the requested variable.

intvalue

Identifies the output parameter that is to hold the integer value of the requested variable.

On successful completion, the function returns one of the following values:

REG_NODATA

A variable was not found. This indicates that the handle was invalid.

REG_INTEGER

An integer type variable was found; the value will be stored in the intvalue variable.

REG_STRING

A string type variable was found; the value will be stored in the strvalue variable.

REG_UNSUPPORTED

An unsupported variable type was found; the value will be void.

Format 2

RegQueryVariable(hkey as integer, name as string, dummy as string, bufsize as integer, buffer as void) as integer.
hKey

Identifies a currently open key or a predefined key. The hKey parameter can have one of the following predefined values:

HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
name

Identifies the name of the requested variable.

dummy

Reserved.

bufsize

Size of the receiving buffer in chars if the buffer is of type string; otherwise, the number of bytes are specified. Must be a variable. After successful return it contains the number of bytes retrieved.

buffer

Buffer to receive the retrieved value of the variable.

Type of registry entry is returned in Microsoft notation:

REG_NONE
Value 0
REG_SZ

Value 1

REG_EXPAND_SZ

Value 2

REG_BINARY

Value 3

REG_DWORD

Value 4

REG_DWORD_LITTLE_ENDIAN

Value 5

REG_DWORD_BIG_ENDIAN

Value 6

REG_LINK

Value 7

REG_MULTI_SZ

Value 8

Example:

Before you start the following example, run the RegOpenKey example.

Dim value as string
Dim hkey1 as integer
Dim name, str, dummy as string
Dim i, i1, rtr, int as integer
Dim bBuf[100] as Byte
Dim cBuf[100] as char

ClrScr()

hkey1 = RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\CA\4 test only")
if hkey1 = 0 then
	Print("RegOpenKey failed.")
	exit
endif

rtr = RegQueryVariable(hkey1, "var_2", str, int)
Print(Str(rtr) + ": var_2 = " + str)
int = 100
str = ""
rtr = RegQueryVariable(hkey1, "var_2", dummy, int, str)
Print(Str(rtr) + ": var_2(" + Str(int) + ") = " + str)
int = 100
str = ""
rtr = RegQueryVariable(hkey1, "var_2", dummy, int, cBuf)
for i1 = 0 to int - 1
	str = str + cBuf[i1]
next i1
Print(Str(rtr) + ": var_2(" + Str(int) + ") = " + str)
int = 100
str = "| "
rtr = RegQueryVariable(hkey1, "var_2", dummy, int, bBuf)
for i1 = 0 to int - 1
	str = str + Str(bBuf[i1]) + " | "
next i1
Print(Str(rtr) + ": var_2(" + Str(int) + ") = " + str)

RegCloseKey(hkey1)