Registry

HKEY_CURRENT_USER - This contains configuration information of a user who is currently logged onto the system. This stores all the user profile data. This actually an alias for a key in the HKEY_USERS sub tree.
HKEY_USERS - This contains all the user profiles on the computer.
HKEY_LOCAL_MACHINE - This contains configuration information particular to the computer, irrespective of which user is logged on.
HKEY_CLASSES_ROOT - This contains data that associates files types with programs and configuration data for COM objects.
HKEY_CURRENT_CONFIG - This contains information about the hardware profile used by the local computer at system startup.


Each key has a large number of subkeys and may actually have a value as well.



Registry Datatypes

REG_SZA fixed-length text string (True or False) values and other short text values usually have this datatype
REG_EXPAND_SZA variable-length text string that can include variables that are resolved when an application or service uses the data
REG_DWORDData represented by a number that is 4 bytes (32 bits) long
REG_MULTI_SZMultiple text strings formatted as an array of null-terminated strings, and terminated by two null characters.



Microsoft.Win32.Registry

This provides base registry keys as shared public (read-only) methods
These can be used to access the subkeys for the corresponding keys

Dim objRegistry As Microsoft.Win32.Registry 


CurrentUser - HKEY_CURRENT_USER
Users - HKEY_USERS
LocalMachine - HKEY_LOCAL_MACHINE
ClassesRoot - HKEY_CLASSES_ROOT
CurrentConfig - CURRENT_CONFIG



Microsoft.Win32.RegistryKey

Dim objRegistryKey As Microsoft.Win32.RegistryKey 



Public Properties

NameRetrieves the name of the key
SubKeyCountRetrieves the total number of subkeys at the base level for the current key
ValueCountRetrieves the count of values in the key



Public Methods

CloseCloses the key and flushes it to disk if the contents have been modified
CreateSubKeyCreates a new subkey or opens an existing subkey
DeleteSubKeyDeletes the specified subkey
DeleteSubKeyTreeDeletes the subkey and any child subkeys recursively
DeleteValueDeletes the specified value from the key
FlushWrites all the sttributes of the specified open registry key into the registry
GetSubKeyNamesGets an array of strings that contain all the value names associated with this subkey
GetValueGets the specified value from the key
GetValueNamesGets an array of strings that contain all the value names associated with this key
OpenSubKeyGets a specified subkey, with the write access as specified.
SetValueSets the specified value



Creating a SubKey

Dim objRegistryKey As RegistryKey 
objRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", True)
objRegistryKey.CreateSubKey("MySubKey")
objRegistryKey.Close()



Deleting a SubKey

Dim objRegistryKey As RegistryKey 
objRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", True)
objRegistryKey.DeleteSubKey("MySubKey")
objRegistryKey.Close()




Reading and Writing

Dim objRegistryKey As RegistryKey 
Dim dcDecimal As Decimal
objRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\MySubKey", True)
objRegistryKey.SetValue("MySubKey", "MyValue")
dcDecimal = objRegistryKey.GetValue("Version", 1.1)






© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext