Search code examples
c#registry

Deleting a single registry value in C#


Is there any way to delete a single registry entry in C#? All the deletion methods will remove the whole subkey rather than a single value.

Registry.SetValue(@"My\Reg\Key\Path", "MyValue", null);

The above example isn't valid to Microsoft.Win32, but hopefully you see what i'm getting at.


Solution

  • Open the appropriate key in read/write mode and invoke the DeleteValue() method:

    var regKey = Registry.LocalMachine.OpenSubKey(@"path\to\subkey",true);
    regKey.DeleteValue("MyValue");