Code Samples
The product includes numerous Visual Basic sample applications. All samples
include complete source code. For more detailed sample code please refer to the
sample applications.
Setting Registry Values
Listing 1 demonstrates setting a registry value.
Private Sub SetValue()
Dim Reg As New RegistryAccessor
' Set the value
With Reg
.ComputerName = "myserver"
.HKEY = REG_HKEY_LOCAL_MACHINE
.SubKey = "software\mykey"
.ValueName = "myvalue"
.Value = "my test value"
End With
End Sub
|
Listing 1 Setting registry values
Querying Registry Values
Listing 2 demonstrates querying a registry value.
Private Sub QueryValue()
Dim Reg As New RegistryAccessor
' Get the value
Dim Value As Variant
With Reg
.ComputerName = "myserver"
.HKEY = REG_HKEY_LOCAL_MACHINE
.SubKey = "software\mykey"
.ValueName = "myvalue"
Value = .Value
End With
End Sub
|
Listing 2 Querying registry values
Enumerating Registry Keys
Listing 3 demonstrates enumerating subkeys of a registry key.
Private Sub EnumerateKeys()
Dim RegDB As New RegistryDatabase
' Open the registry key
Dim RegKey As RegistryKey
Set RegKey = RegDB.OpenKey(REG_HKEY_LOCAL_MACHINE, "software\mykey")
' Enumerate the subkeys (using for construct)
Dim i As Long
For i = 1 To RegKey.SubKeys.Count
Dim SubKey As RegistryKey
Set SubKey = RegKey.SubKeys(i)
' Process the subkey
Next
End Sub
|
Listing 3 Enumerating registry keys
Enumerating Registry Values
Listing 3 demonstrates enumerating values of a registry key.
Private Sub EnumerateValues()
Dim RegDB As New RegistryDatabase
' Open the registry key
Dim RegKey As RegistryKey
Set RegKey = RegDB.OpenKey(REG_HKEY_LOCAL_MACHINE, "software\mykey")
' Enumerate the values (using for each construct)
Dim Value As RegistryValue
For Each Value In RegKey.Values
' Process the value
Next
End Sub
|
Listing 4 Enumerating registry values
|