The following code includes classes registry, regkey, regkeys, regvalue and regvalues. All together they provide view, read, write and delete functionality for the System Registry. Examples showing how to use this class are coming soon.
Create Registry object before using any other class from this library. This object contains API declarations the other classes use.
LOCAL rg As Registry
rg = CREATEOBJECT("Registry")
The next snip opens Software key in HKEY_LOCAL_MACHINE and adds _test subkey to it.
LOCAL rgkey As regkey
rgkey = CREATEOBJECT("regkey",;
HKEY_LOCAL_MACHINE, "Software")
WITH rgkey
IF .OpenKey()
.CreateSubkey("_test", "")
ENDIF
ENDWITH
And the last one adds several values to a key.
WITH rgkey
IF .OpenKey()
.SetValue("TestValue0", 0, 16) && REG_NONE
.SetValue("TestValue1", 1, "abc") && REG_SZ
.SetValue("TestValue3", 3, "abc") && REG_BINARY
.SetValue("TestValue4", 4, "128") && REG_DWORD
ENDIF
ENDWITH
|
Imports Microsoft.Win32
Module Module1
Sub Main()
Dim r As Registry
REM: ClassesRoot, CurrentConfig, CurrentUser
REM: LocalMachine, Users
Dim k As RegistryKey = r.CurrentConfig
REM: recursive procedure
PrintKey(k, 0)
Console.Write("Press Enter to close this window...")
Console.ReadLine()
End Sub
Sub PrintKey(ByRef key As RegistryKey, ByVal level As Integer)
Dim s As String = ""
Dim name As String = key.Name
Dim pos As Integer = InStrRev(name, "\")
If pos > 0 Then name = Mid(name, pos + 1)
Console.WriteLine(s.PadRight(level * 3, " ") & name)
If key.SubKeyCount = 0 Then Exit Sub
Dim subkeynames() As String = key.GetSubKeyNames()
Dim subkeyname As String
For Each subkeyname In subkeynames
Dim subkey As RegistryKey
Try
subkey = key.OpenSubKey(subkeyname)
PrintKey(subkey, level + 1)
subkey.Close()
Catch
End Try
Next
End Sub
End Module
|