deleting a subkey

  • Thread starter Thread starter aaronfude
  • Start date Start date
A

aaronfude

Hi,

I have the following code (from a project I found on the web) that
deletes a subkey.

RegistryKey root = Registry.ClassesRoot;
root.DeleteSubKey("AllFilesystemObjects\\shellex\\ContextMenuHandlers\\CleanVS");


It throws the following exception:

Void DeleteSubKey(System.String, Boolean)
System.ArgumentException: Cannot delete a subkey tree because the
subkey does not exist.
at Microsoft.Win32.RegistryKey.DeleteSubKey(String subkey, Boolean
throwOnMis
singSubKey)
at Microsoft.Win32.RegistryKey.DeleteSubKey(String subkey)
at CleanVS.CleanVS.UnregisterServer(String zRegKey)

I checked manually that the subkey does exist, and in fact it gets
deleted during this operation! ...But I still get the error! Any
ideas?!

By the way, the key was created with this command:

root = Registry.ClassesRoot;
rk =
root.CreateSubKey("AllFilesystemObjects\\shellex\\ContextMenuHandlers\\CleanVS");
rk.SetValue("", clsid);
rk.Close();


Very many thanks in advance!
 
I'm guessing, this may not be the right news group for this question?
Can someone recommend the right news group?

Thanks!
 
I'm guessing, this may not be the right news group for this question?
Can someone recommend the right news group?

The group is fine. But I can't reproduce the problem, the key gets
deleted without any exception being thrown here. Can you put together
a short example that reproduces the problem you're seeing?



Mattias
 
Hi, thanks for the answer.

Your response prompted me to put a couple of printing statements into
my method. I realized that what's happens is that the method is called
twice (which explains it).

Why it is called twice is not a mystery. Here's the excerpt from Main:

Assembly asm = Assembly.GetExecutingAssembly();
RegistrationServices reg = new RegistrationServices();
if (unregister) {
System.Console.Error.WriteLine("About to call
\"UnregisterAssemply\"");
reg.UnregisterAssembly(asm);
System.Console.Error.WriteLine("About to call \"Unregister\"");
CleanVS.UnregisterServer("");
System.Console.Error.WriteLine("Done calling \"Unregister\"");
}

and I learn that CleanVS.UnregisterServer is called automatically from
reg.UnregisterAssembly(asm) and then by me manually? Voila.

But is this defined behavior? Should I just comment out
CleanVS.UnregisterServer("")? Once again, this is not my code, but
something I found at
http://www.informit.com/articles/article.asp?p=169474&redir=1&rl=1

Thanks for responding and thank you very much in advance,

Aaron Fude
 
Back
Top