The registry object can be used to read from, and write to the registry.
Properties | Description |
ComputerName | Computer on which the (remote) registry should be connected |
Disposition | Key state (0=Newly created, 1=Already existing) |
KeyEnumName | Key name as a result of an enumeration |
KeyName | Key name for single registry actions |
KeyRoot | Registry hive to be processed (LocalMachine, CurrentUser, etc.) |
KeyType | Registry Key Type (REG_SZ, REG_DWORD, etc.) |
KeyValue | Retrieved value, or value to be set. |
RegMode64 | Switch the ‘RegistryView’ for 64-bit systems (True=64-bit view, False=32-bit view) |
Result | Legible result text. |
ResultCode | Numeric result code |
ValueName
|
Registry value name
|
Methods | Description |
DeleteKey | Delete the specified key.
Function DeleteKey(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String) As Boolean) The function will use the property values, if parameters are omitted. |
DeleteValue | Delete the specified value.
Function DeleteValue(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String, Optional KeyValueName As String) The function will use the property values, if parameters are omitted. |
EnumerateKeys | Iterate through all (sub)keys of a key
Function EnumerateKeys(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String, Optional KeyIndex As Long) The function will use the property values, if parameters are omitted. |
EnumerateKeyValues | Iterate through all values of a key
Function EnumerateKeyValues(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String, Optional KeyIndex As Long) The function will use the property values, if parameters are omitted. |
GetKeyValue | Retrieve the value of a key
Function GetKeyValue(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String, Optional KeyValueName As String) The function will use the property values, if parameters are omitted. |
WriteKey | Write a (new) key into the registry
Function WriteKey(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String) The function will use the property values, if parameters are omitted. |
WriteKeyValue | Write a (new) value into the registry
Function WriteKeyValue(Optional Computer As String, Optional KeyRoot As Hkey, Optional KeyName As String, Optional KeyValueName As String Optional KeyValue As Variant, Optional KeyType As RegKeyType) The function will use the property values, if parameters are omitted. |
All methods return a Boolean value where ‘True’ indicates a successful execution of the function.
Usage:
Sub Scense_Main() 'Registry Key Root Const HKEY_CLASSES_ROOT = &H80000000 Const HKEY_CURRENT_USER = &H80000001 Const HKEY_LOCAL_MACHINE = &H80000002 Const HKEY_USERS = &H80000003 Const HKEY_PERFORMANCE_DATA = &H80000004 Const HKEY_CURRENT_CONFIG = &H80000005 Const HKEY_DYN_DATA = &H80000006 'Registry Key Type Const REG_SZ = 1 Const REG_EXPAND_SZ = 2 Const REG_DWORD = 4 'Write a value (Method 1) With Registry .KeyRoot = HKEY_CURRENT_USER .KeyName = "Software\Test" .ValueName = "Test" .KeyValue = "aaaaa" .KeyType = REG_SZ If Not .WriteKeyValue Then WriteScenseLog .Result End If End With 'Write a value (Method 2) With Registry If Not .WriteKeyValue(, HKEY_CURRENT_USER, "Software\Test", "Test", "bbbbb", REG_SZ) Then WriteScenseLog .Result End If End With 'Read a value With Registry If .GetKeyValue(, HKEY_CURRENT_USER, "Software\Test", "Test") Then WriteScenseLog .KeyValue Else WriteScenseLog .Result End If End With 'Delete a value With Registry If Not .DeleteValue(, HKEY_CURRENT_USER, "Software\Test", "Test") Then WriteScenseLog .Result End If End With End Sub