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 data type
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

Microsoft.Win32.Registry oRegistry; 

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



Microsoft.Win32.RegistryKey

Microsoft.Win32.RegistryKey oRegistryKey; 


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

Microsoft.Win32.RegistryKey oRegistryKey; 

oRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true);
oRegistryKey.CreateSubKey("MySubKey");
oRegistryKey.Close();


Deleting a SubKey

Microsoft.Win32.RegistryKey oRegistryKey; 

oRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software", true)
oRegistryKey.DeleteSubKey("MySubKey");
oRegistryKey.Close();



Reading and Writing

Microsoft.Win32.RegistryKey oRegistryKey; 
decimal dcDecimal;

oRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\MySubKey", true);
oRegistryKey.SetValue("MySubKey", "MyValue");
dcDecimal = objRegistryKey.GetValue("Version", 1.1);


Microsoft.Win32.RegistryKey oRegistryKey; 
string s64Or32 = "";

oRegistryKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\MySubKey", true);
s64Or32 = oRegistryKey.GetValue("Bitness","N/A");




© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext