2

Whenever I run the code below it throws an exception that the subkey does not exist though it actually exists. Am I doing something incorrectly? The purpose is to delete subkeys under a registry key recursively. My visual studio is running on x64:

string registryKey = @"Software\Google\Chrome";
RegistryKey hkcuChrome = Registry.CurrentUser.OpenSubKey(registryKey, writable: true);
        string[] hkcu_subkeys = hkcuChrome.GetSubKeyNames();
        if (hkcuChrome != null)
        {
            for (int i = 0; i < hkcu_subkeys.Length; i++)
            {
                hkcuChrome.DeleteSubKeyTree(hkcu_subkeys[i]);

            }
        }

        hkcuChrome.Close();
lee-m
  • 2,269
  • 17
  • 29
  • 1
    What's `String.Format` supposed to be accomplishing here? Your input is almost certainly not a format string. – Jeroen Mostert Aug 10 '22 at 09:05
  • Hi @JeroenMostert sorry, error with copy pasting, I've modified the code. – carlplusplus Aug 10 '22 at 09:11
  • 2
    Possible duplicate of https://stackoverflow.com/questions/2959419/registry-in-net-deletesubkeytree-says-the-subkey-does-not-exists-but-hey-it – sgmoore Aug 10 '22 at 09:16
  • 1
    Does this answer your question? [Registry in .NET: DeleteSubKeyTree says the subkey does not exists, but hey, it does!](https://stackoverflow.com/questions/2959419/registry-in-net-deletesubkeytree-says-the-subkey-does-not-exists-but-hey-it) – lee-m Aug 10 '22 at 09:20
  • No unfortunately – carlplusplus Aug 10 '22 at 09:32
  • I've been searching all over stackoverflow and none even answered my question. – carlplusplus Aug 10 '22 at 09:37

0 Answers0