I was trying to use switch to handle all possibles hives from registry - later on, i want to generate SubKeyNames for key (together with hive) provided as an input, but i still get errors like: ‘A local variable named ‘regKey’ is already defined in this scope’ ‘The name ‘regKey’ does not exists in the current context’
switch (hive) {
case "HKEY_CLASSES_ROOT":
RegistryKey regKey=Registry.ClassesRoot.OpenSubKey(key,false);
break;
case "HKEY_CURRENT_USER":
RegistryKey regKey=Registry.CurrentUser.OpenSubKey(key,false);
break;
case "HKEY_LOCAL_MACHINE":
RegistryKey regKey=Registry.LocalMachine.OpenSubKey(key,false);
break;
case "HKEY_USERS":
RegistryKey regKey=Registry.Users.OpenSubKey(key,false);
break;
case "HKEY_CURRENT_CONFIG":
RegistryKey regKey=Registry.CurrentConfig.OpenSubKey(key,false);
break;
default:
throw new System.Exception("Incorrent hive");
}