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_SZ | A fixed-length text string (True or False) values and other short text values usually have this data type |
REG_EXPAND_SZ | A variable-length text string that can include variables that are resolved when an application or service uses the data |
REG_DWORD | Data represented by a number that is 4 bytes (32 bits) long |
REG_MULTI_SZ | Multiple 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
Name | Retrieves the name of the key |
SubKeyCount | Retrieves the total number of subkeys at the base level for the current key |
ValueCount | Retrieves the count of values in the key |
Public Methods
Close | Closes the key and flushes it to disk if the contents have been modified |
CreateSubKey | Creates a new subkey or opens an existing subkey |
DeleteSubKey | Deletes the specified subkey |
DeleteSubKeyTree | Deletes the subkey and any child subkeys recursively |
DeleteValue | Deletes the specified value from the key |
Flush | Writes all the sttributes of the specified open registry key into the registry |
GetSubKeyNames | Gets an array of strings that contain all the value names associated with this subkey |
GetValue | Gets the specified value from the key |
GetValueNames | Gets an array of strings that contain all the value names associated with this key |
OpenSubKey | Gets a specified subkey, with the write access as specified. |
SetValue | Sets 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