Overview
CreateSubKey
DeleteSubKey
DeleteSubKeyTree
DeleteValue
GetSubKeyNames
GetValue
GetValueKind
GetValueNames
RootKey
SetBinaryValue
SetDWORDValue
SetStringValue
SetMultiStringValue
SubKeyCount
ValueCount
Overview Top
The Registry library allows access to the desktop or the device registry.
Writing to the registry should be done with great care as incorrect settings could damage the computer.
The Registry library includes two files: RegistryDevice.dll - for the device and RegistryDesktop.dll - for the desktop.
Prior to using this library you should add a reference to the library using the Components dialog, add an object of this type and initialize the object with the New1 method.
The registry is divided to four (on the device) or five (on the desktop) root keys.
Using the RootKey method you can choose the relevant root key.
Example:
'Add a Registry object named reg.
Sub Globals
key = "Software\My Application"
End Sub
Sub App_Start
form1.Show
reg.New1
reg.RootKey(reg.rtCurrentUser)
ErrorLabel(NotCreatedYet)
msgbox("The value is: " & reg.GetValue(key,"Settings"))
return
NotCreatedYet: 'creates the subkey if it didn't exist
reg.CreateSubKey("",key)
msgbox("The key was created.")
End Sub
Sub Form1_Close
reg.SetStringValue(key,"Settings","Something important that
should be saved in the registry.")
End Sub
CreateSubKey Top
Creates a new subkey.
Syntax: CreateSubKey (SubKey As String, NewSubKey As String)
SubKey - The parent subkey.
NewSubKey - The new subkey that should be created.
CreateSubKey does nothing if the new subkey already exists.
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.CreateSubKey("Software","My Application")
End Sub
Example: (same as the above example)
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.CreateSubKey("","Software\My Application")
End Sub
DeleteSubKey Top
Deletes an existing subkey, including the values it contains.
On the device and on several windows versions it will delete the subkey even if it contains other subkeys.
Syntax: DeleteSubKey (SubKey As String, RemoveKey)
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.DeleteSubKey("Software","My Applicaton")
End Sub
Example: (same as the above example)
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.DeleteSubKey("","Software\My Applicaton")
End Sub
DeleteSubKeyTree Top
Deletes a subkey and all the values and subkeys it contains.
Syntax: DeleteSubKeyTree (SubKey As String, RemoveKey As String)
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.DeleteSubKeyTree("","Software\My Applicaton")
End Sub
DeleteValue Top
Deletes the specified value.
Syntax: DeleteValue (SubKey As String, ValueName As String)
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.DeleteValue("Software\My Application","Some Value")
End Sub
GetSubKeyNames Top
Returns an array filled with the names of all subkeys in the specified subkey.
Syntax: GetSubKeyNames (SubKey As String) As String()
Example:
'Add a Registry object named reg.
Sub Globals
dim names(0) As String
End Sub
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
names() = reg.GetSubKeyNames("Software\My Application")
for i = 0 to ArrayLen(names())-1 'Show all subkeys found
msgbox(names(i))
next
End Sub
GetValue Top
Returns the actual value of the specified value in the subkey.
Syntax: GetValue (SubKey As String, ValueName As String) As Object
GetValue can return four different types of data:
String - If the value is of type REG_SZ.
Integer - If the value is of type REG_DWORD
Bytes Array - If the value is of type REG_BINARY.
String Array - If the value is of type REG_MULTI_SZ.
Example:
'Add a Registry object named reg.
Sub Globals
dim files(0) As String
dim binary(0) As Byte
End Sub
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
key = "Software\My Application"
number = reg.GetValue(key, "Number Of Items") 'Number Of Items is of type REG_DWORD
name = reg.GetValue(key, "User Name") 'User Name is of type
REG_SZ
files() = reg.GetValue(key, "RecentFiles") 'Recent file is of type REG_MULTI_SZ (multi - string)
binary() = reg.GetValue(key,"BinaryValue") 'BinaryValue is of type REG_BINARY
End Sub
GetValueKind Top
Returns a string that describes the value's type.
Syntax: GetValueKind (SubKey As String, ValueName As String) As String
The returned value can be:
REG_SZ - for a simple string value.
REG_DWORD - for a simple integer value.
REG_BINARY - for an array of bytes value.
REG_MULTI_SZ - for an array of strings value.
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
msgbox(reg.GetValueKind("Software\My Application","Some Value"))
End Sub
GetValueNames Top
Returns an array filled with the names of all values in the specified subkey.
Syntax: GetValueNames (SubKey As String) As String()
Example:
'Add a Registry object named reg.
Sub Globals
dim names(0) As String
End Sub
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
names() = reg.GetValueNames("Software\My Application")
for i = 0 to ArrayLen(names())-1 'Show all values found
msgbox(names(i))
next
End Sub
RootKey Top
Sets the current root key.
Syntax: RootKey (Root As RegistryKey)
Root must be one of these properties:
rtClassesRoot - for HKEY_CLASSES_ROOT.
rtCurrentConfig - for HKEY_CURRENT_CONFIG (only on the desktop).
rtCurrentUser - for HKEY_USERS
rtLocalMachine - for HKEY_LOCAL_MACHINE
rtUsers - for HKEY_USERS
You must set the root key using this method before trying to access the registry.
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
...
End Sub
SetBinaryValue Top
Sets the value of the specified key value.
Syntax: SetBinaryValue (SubKey As String, ValueName As String, Value As Byte() )
If the ValueName does not exist a new value will be created.
Example:
'Add a Registry object named reg.
Sub Globals
dim binary(3) As Byte
End Sub
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
binary(0) = 100
binary(1) = 254
binary(2) = 12
reg.SetBinaryValue("Software\My Application","Binary Value",
binary())
End Sub
SetDWORDValue Top
Sets the value of the specified key value.
Syntax: SetDWORDValue (SubKey As String, ValueName As String, Value As Int32)
If the ValueName does not exist a new value will be created.
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.SetDWordValue("Software\My Application","DWORD Value", 33)
End Sub
SetStringValue Top
Sets the value of the specified key value.
Syntax: SetStringValue (SubKey As String, ValueName As String, Value As String)
If the ValueName does not exist a new value will be created.
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
reg.SetStringValue("Software\My Application","Sring Value", "Some
string")
End Sub
SetMultiStringValue Top
Sets the value of the specified key value.
Syntax: SetMultiStringValue (SubKey As String, ValueName As String, Value As String() )
If the ValueName does not exist a new value will be created.
Example:
'Add a Registry object named reg.
Sub Globals
dim strings(3) As String
End Sub
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
strings(0) = "Some string 1"
strings(1) = "Some string 2"
strings(2) = "Some string 3"
reg.SetMultiStringValue("Software\My Application","Multi String
Value", strings())
End Sub
SubKeyCount Top
Returns the number of subkeys under the specified subkey.
Syntax: SubKeyCount (SubKey As String) As Int32
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
c = reg.SubKeyCount("Software\My Application")
End Sub
ValueCount Top
Returns the number of values under the specified subkey.
Syntax: ValueCount (SubKey As String) As Int32
Example:
Sub App_Start
reg.New1
reg.RootKey(reg.rtCurrentUser)
c = reg.ValueCount("Software\My Application")
End Su