1

I'm trying to delete a registry from the Local_Machine\Software in the registry. I made a key titled "DeleteMe" as a test to try it out, but I can't get it to work.

I've tried multiple options, and they all say that the "subkey" "subkeytree" and "value" do not exist, but they do exist! And I hope I'm using the right terminology here. To its HKEY_LOCAL_MACHINE\SOFTWARE\DeleteMe, I want it and all the sub keys/values deleted... (I hope the key is the right terminology. They look just like folders, but when right clicked on, they have the option "copy key name").

So far the best looking thing I've tried was this and I am running as an administrator on Windows 7 (but I want this to work regardless of the OS).

string keyName = @"Software\DeleteMe";
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(keyName, true))
{
    if (key == null)
    {
        MessageBox.Show("Not Found");
    }
    else
    {
        key.DeleteSubKeyTree("DeleteMe");
    }
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
NightsEVil
  • 507
  • 2
  • 13
  • 21
  • You have any current code you'd like to share so we could pin point your exact issue? – Jeff Jun 17 '10 at 01:38
  • yes i do and iv figured out that it works for CurrentUser.. but for LocalMachine its a permissions problem, is there a way to force it to delete? – NightsEVil Jun 17 '10 at 02:47
  • If you're running into a UAC issue then maybe it's time you make your application raise the UAC level on the O/S in order to prompt the user for the appropriate access. See this article for details: http://www.aneef.net/2009/06/29/request-uac-elevation-for-net-application-managed-code/ – Jeff Jun 17 '10 at 13:29
  • I spent hours debugging this, and what finally did it for me was the answer here: http://stackoverflow.com/questions/13728491/opensubkey-returns-null-for-a-registry-key-that-i-can-see-in-regedit-exe – KayakinKoder Jun 09 '16 at 16:13

1 Answers1

1

Check out this previous answer on StackOverflow. A pretty good summation of the process. Anything you're doing different from this?

How to delete a registry value in C#

Community
  • 1
  • 1
Jeff
  • 1,742
  • 5
  • 24
  • 39
  • yes iv looked there and EVERY thing i tried i get "cannot delete a subkey tree because the subkey does not exist) so i think im missing something.. donno what tho. – NightsEVil Jun 17 '10 at 02:02
  • Again - have any code we can look at to see where an issue may lie? O/S? Running application as administrator if on Vista or Windows 7? – Jeff Jun 17 '10 at 02:17