C# Registry Operations
The registry is an optimal location for saving information about your application as well as individual user settings.
The Registry comprises a number of logical sections called Hives. The following are the predefined keys that are used by the system.
- HKEY_CURRENT_USER
- HKEY_USERS
- HKEY_LOCAL_MACHINE
- HKEY_CLASSES_ROOT
- HKEY_CURRENT_CONFIG
Each key has many subkeys and may have a value.
When programming in C#, you can choose to access the registry via either the functions provided by C# or the registry classes of the .NET Framework. The operations on the registry in .NET can be done using two classes of the Microsoft.Win32 Namespace: Registry class and the RegistryKey class. The Registry class provides base registry keys as shared public methods:
Creating a Registry Entry
Above code shows how to create a subkey under HKLM\Software called AppReg.
Deleting a Subkey
The following C# program shows how to create a registry entry , set values to registry entries, retrieve values from registry and delete keys on Registry. Drag and drop four buttons on the form control and copy and paste the following source code.
Full Source C#- An overview of Microsoft .Net Framework
- An introduction to C#
- C# Version History
- C# and VB.NET
- C# and JAVA
- C# sample programs
- C# console based application
- C# windows based application
- C# command line tools
- C# command line arguments
- Difference between .Net Framework and .Net Core
- C# Repository Design Pattern