C# Edit Registry Keys or Values

First

Before starting to edit registry values/keys, include in your project’s source this namespace Microsoft.Win32. It will give you access to the required Registry functions.
So, make sure you add this:

In order to edit anything, you must:

1. open the key where you want to edit (set a path)
2. add/delete/edit what you want
3. close the key

Note: in this tutorial I used Windows’ startup Key (path), but you can use anything you want.
So your snippet will look like this:


Creating a Key

A key is a subfolder, in which you can add multiple values.
To create a key:

Deleting a Key

In order to delete a key, you have to do the same thing: set the path then simply delete it.

Adding/Editing a value

Before doing this, you have to set the path to the key where you want to add that value. You can use the code below for adding or editing values.

Reading a value

You can get a value from a key by knowing it’s name:

Deleting a value

And finally, when we got bored of values, we can delete them:

C#
1
2
3
4
5
6
7
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
//deleting the value
key.DeleteValue("someValue");
key.Close();
Previous
Next Post »