Previous Topic: RegSetValue - Associate the Registry Key with a Text StringNext Topic: SetMode64 - Accessing Windows 64-bit Registry and File System


RegSetVariable - Store a Variable in the Registry Key

Valid on Windows

The RegSetVariable function stores a variable in the specified registry key.

Function format:

RegSetVariable(hKey as Integer, name as String, value as Integer) as Boolean
RegSetVariable(hKey as Integer, name as String,	value as String) as Boolean
RegSetVariable(hkey as integer, name as string, buffer as void, bufsize as integer) as integer.
RegSetVariable(hkey as integer, name as string, buffer as void, bufsize as integer, type 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 variable that is to be set.

value

Identifies the string or Integer value that is to be set in the variable.

buffer

Buffer containing the value to be set in the variable.

bufsize

Size of the buffer in chars if the buffer is of type string or array of type char; otherwise, the number of bytes are specified.

type

The type of registry entry.

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

On successful completion, the function returns TRUE; otherwise, it returns FALSE.

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)