Reading and Writing Values From/Into Windows Registry

Here is the code for read the registry value using C#.

First I’m creating registry key value and string value in local machine as follows,

myKey –> key value
myValue –> string name
myReturnValue –> string value

Code for Registry value Reading using C#…

using Microsoft.Win32;

try
{
RegistryKey registry = Registry.LocalMachine.CreateSubKey(”SOFTWARE\\myKey”);
if (registry != null)
{
MessageBox.Show(registry.GetValue(”myValue”));
registry.Close();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}
 

Code for Values writing in Registry using C#.

using Microsoft.Win32;

try
{
RegistryKey registry = Registry.LocalMachine.CreateSubKey(”SOFTWARE\\myKey”);
if (registry != null)
{
registry.SetValue(”myValue”, “myReturnValue”);
registry.Close();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.ToString());
}

Bookmark It

Click here if you need a Website


Leave a Reply