c# get registry value code example

Example: c# read registry data

//Writing
//accessing the CurrentUser root element  
//and adding "OurSettings" subkey to the "SOFTWARE" subkey  
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\OurSettings"); 

//storing the values  
key.SetValue("Setting1", "This is our setting 1");  
key.SetValue("Setting2", "This is our setting 2");  
key.Close(); 

//Reading
//opening the subkey  
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\OurSettings");  
              
//if it does exist, retrieve the stored values  
if (key != null)  
{  
    Console.WriteLine(key.GetValue("Setting1"));  
    Console.WriteLine(key.GetValue("Setting2"));  
    key.Close();  
}