Registry Functions

These functions can be used to manipulate the registry:

RegDeleteValue Deletes a value
RegDeletePath Deletes an entire path (hive)
RegEnumElement Returns an element of an enumeration
RegEnumPaths Enumerates all keys
RegEnumValues Enumerates all values
RegPathExists Checks if a specified registry-path exists
RegReadValue Reads a value from the registry
RegWriteValue Writes a value to the registry

The following parameters can be used with the functions above:

Path A registry path in the form "ROOT\Path\Path\Value".

"ROOT" can be one of the following values:

HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_CLASSES_ROOT
HKEY_USERS

You can also use the short form:

HKCU
HKLM
HKCR
HKUS

"Path" is the path inside the registry, for example "Software\Microsoft\Windows".

"Value" is the the name of the desired value, for example "CountUsers" or "@"
if you want to access the (Default) value.

 

DataType The type of value to access (currently only used by the RegWriteValue function)

1 = REG_SZ (String)
2 = REG_DWord (Numeric)
3 = REG_BINARY (Binary Data)

Remarks about enumeration:

If the count of elements is not known or it varies from computer to computer you should use RegEnumValues or RegEnumPaths.

For example, the registry-path "HKLM\Software\Test" may contain three keys ("\Test1", "\Test2", "\Test3") and two values ("MaxCount", "MinCount"). To enumerate the keys ("\Test1"...) use the RegEnumPaths function. To enumerate the two values ("MaxCount, "MinCount") use the RegEnumValues function. To retrieve on of the enumerated items, use the RegEnumElement function.

Remarks about accessing binary (REG_BINARY) values:

X-Setup uses special function when accessing binary (Type = 3) values. You can simply write the values to the registry as they appear in RegEdit.EXE but it's highly important not to forget the " " around the value. This is because VBScript will remove any zeros if the string is not surrounded by ". For example, if you execute this command:

   Call RegWriteValue("Value",01FF,3) 'CRASH!!!

X-Setup will crash because "1FF" can't be written to the registry - The leading zero has been removed by VBScript. On the other hand, this function will work fine:

   Call RegWriteValue("Value","01FF",3)

Examples:

s=RegReadValue("HKEY_LOCAL_MACHINE\Software\Microsoft\Exchange") 'read a value with long form of ROOT
s=RegReadValue("HKLM\Software\Microsoft\Exchange")               'same using short form of ROOT

s=RegReadValue("HKLM\Software\Microsoft\Windows\CurrentVersion\@") 'reading (default) value

b=RegPathExists("HKLM\Software\Microsoft") 'check if path exists

Call RegWriteValue("HKLM\Software\Microsoft\TestVal1","X-Setup",1) 'writing string to registry
Call RegWriteValue("HKLM\Software\Microsoft\TestVal2",123,2)       'writing DWord to registry
Call RegWriteValue("HKLM\Software\Microsoft\@","StringData",1)     'writing (default) value