views:

118

answers:

2

Hi,

Trying to delete a subkey tree: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.hdr. .hdr subkey has one subkey, no values. So I use this code:

RegistryKey FileExts = Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts");
RegistryKey faulty = FileExts.OpenSubKey(".hdr");
Debug.Assert (faulty != null && faulty.SubKeyCount != 0);
faulty.Close();
FileExts.DeleteSubKeyTree(".hdr");

And I get the ArgumentException with message "Cannot delete a subkey tree because the subkey does not exist."

WTF? I checked and asserted it did exist?

Status update

Seeking with Process Monitor, the subkey of ".hdr" gets a ACCESS DENIED error when running the code. I checked the autorizations, but they look fine?

A: 

Found a solution, which raises other another question...

After pointing the ACCESS DENIED error with Process Monitor, I just tried to delete subkeys individually:

RegistryKey hdr = FileExts.OpenSubKey(".hdr", true);
foreach (String key in hdr.GetSubKeyNames())
   hdr.DeleteSubKey(key);
hdr.Close();
FileExts.DeleteSubKeyTree(".hdr");

It worked fine, so it's not a permission problem!

For a reason I don't understand, DeleteSubKeyTree needed an empty tree to work.

An explanation, anyone?

CharlesB
A: 

hi,

i am trying to remove sub-keys using foreach and is giving for following exception ex: "Registry key has subkeys and recursive removes are not supported by this method." implementation is same as yours.

thanks.

Kinjal
Hi Kinjal, you should post your own question, instead of answering this question. Also give more details and code.
CharlesB