1

I'm trying to read and write to the same registry key. However I can't seem to access it. I've checked the path a million times and it's correct.

RegistryKey key = Registry.LocalMachine.OpenSubKey("HKEY_CLASSES_ROOT\\apart\\Shell\\Open\\Command");
MessageBox.Show(key.ToString());
Dave Zych
  • 21,581
  • 7
  • 51
  • 66
Amorphous
  • 675
  • 1
  • 8
  • 26
  • Please also see if [Cannot access HKEY_CLASSES_ROOT\Installer on Windows Server 2008 Enterprise](http://stackoverflow.com/questions/9180563/cannot-access-hkey-classes-root-installer-on-windows-server-2008-enterprise) helps solve your issue (FYI all I did was Google `C# OpenSubKey returns null`) – tnw Sep 22 '14 at 20:35

2 Answers2

6

LocalMachine corresponds to HKEY_LOCAL_MACHINE.

ClassesRoot represents HKEY_CLASSES_ROOT.

Try

RegistryKey key = Registry.ClassesRoot.OpenSubKey("apart\\Shell\\Open\\Command");
AlexD
  • 32,156
  • 3
  • 71
  • 65
1

You might want to try the following:

RegistryKey key = Registry.ClassesRoot.OpenSubKey("apart\\Shell\\Open\\Command");
MessageBox.Show(key.ToString());

Note the ClassesRoot instead of LocalMachine.