How to read Windows Registry?
.Net, Add Registry Data, API, C#, HKEY_CURRENT_USER, read Windows Registry, Registry, RegistryKey, RegistryKey class, Windows Registry,
In .NET, the Registry and RegistryKey classes can be used to read and write registry ...
In this article, I will explain how to read Windows Registry. First part of this article explains how to add your own registry entries to test the program.
Here are the step:
Add Registry Data
Following text is a actual registry information. Copy and paste this content in a text file and save as with extention .reg. and double click on the file.
/*Windows Registry Editor Version 5.00
Read the Registry Data
- Create two RegistryKey variables.
- Create object od sealed class as shown below with first parameter as HKEY (main root key name) and second as "" for local machine.
- Create sub key from where one would like to read information.
- Use Getvalue method of RegistryKey class for reading data for a particular node key information. Here DSN,Server,Password are nodes.
This source code reads the registry data which you have just added to your registry.
public class Class1
// TODO: Add Constructor Logic here
public static int Main(string args)
RegistryKey TAWKAY = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.CurrentUser,"");
string subkey = "Software\\TAW\\BSE";
SUBKEY = TAWKAY.OpenSubKey(subkey);
object dsn = SUBKEY.GetValue("DSN");
object user = SUBKEY.GetValue("user");
object password = SUBKEY.GetValue("password");
object server = SUBKEY.GetValue("server");