Create, read, write
and delete from registry using C#
In this blog, I’m explaining how to create a key in registry
from C# application and how to read, write and delete it.
RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\TESTINGREGISTRYKEY", RegistryKeyPermissionCheck.ReadWriteSubTree);
This statement will create a key in registry.
Once you have created a key in registry, now you want to
write a value in it but before you write the key, you have to open it like
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\TESTINGREGISTRYKEY", RegistryKeyPermissionCheck.ReadWriteSubTree);
This statement open the key for you and now you have the
access to the key.
This statement will write the value ‘true’ with
Now you have written the key value in registry and you want
You can write the following statement to get the value from
the key value in registry.
object flag = key.GetValue("NotificationStatus");
I have taken a object type variable to receive the
value coz the GetValue method returns the object type value.
This statement deletes the key value from the