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

CRUD in Registry in C#


C# C# 
Ratings:
0 Comment(s)
 1936  View(s)
Rate this:

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.

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.


Don't want to miss updates? Please click the below button!

Follow MindStick