Search code examples
c#registry

How to delete a Registry key?


I want to run this DOS command in C#, without executing a DOS command.

REG DELETE HKLM\SOFTWARE\Wow6432Node\WindowsApplication1\Status /f

Solution

  • Here's one approach. Note that you have to pass true to OpenSubKey in order to get Write permission.

    var hklm = Microsoft.Win32.Registry.LocalMachine;
    var subkey = hklm.OpenSubKey("Software\\Wow6432Node\\WindowsApplication1", true);
    subkey.DeleteSubKey("Status");