blog

Home / DeveloperSection / Blogs / CRUD in Registry in C#

CRUD in Registry in C#

Abhishek Singh3935 16-Jan-2014

In this blog, I’m explaining how to create a key in registry from C# application and how to read, write and delete it.

Create

RegistryKey key = Registry.CurrentUser.CreateSubKey(@"SOFTWARE\TESTINGREGISTRYKEY", RegistryKeyPermissionCheck.ReadWriteSubTree);

This statement will create a key in registry. 

Write

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 this:

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.

key.SetValue("NotificationStatus",true);

This statement will write the value ‘true’ with name ‘NotificationStatus’. 

Read

Now you have written the key value in registry and you want read it.

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. 

Delete
key.DeleteValue("NotificationStatus");

This statement deletes the key value from the registry.


Updated 18-Sep-2014
I am a Software Trainee in Mindstick on .net Technology

Leave Comment

Comments

Liked By