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();