views:

16

answers:

1

Ive made a key in HKEY_LOCAL_MACHINE\Software\MyAppName (with regedit (ive rebootet)), but when i try to list them all out "MyAppName" does not show... :( any clues?

rkey = Registry.LocalMachine.OpenSubKey("Software");
foreach (string subkey in rkey.GetSubKeyNames())
{
WriteToLogFile("subkey: " + subkey);
}
+3  A: 

I'm going to apply my psychic debugging powers, and guess that you have (a) a 64-bit operating system, and (b) Visual Studio 2010.

By default, when you create a new executable project in VS2010, it sets the project options to build for the x86 platform. (Previous versions of Visual Studio targeted "Any Platform", which would JIT to x86 code on a 32-bit OS, and x64 code on a 64-bit OS. But this caused other headaches, so they changed the default in VS2010.)

On a 64-bit OS, 32-bit apps have their own virtualized copy of HKLM\Software. MS did that for compatibility reasons, so that 32-bit apps wouldn't stomp on the settings of 64-bit apps. So when your 32-bit app goes looking for HKLM\Software, it's actually getting HKLM\Wow6432Node\Software.

Four easy fixes for this:

  • Leave your application as 32-bit, but explicitly request the 64-bit Registry. This is probably the simplest solution.
  • When you go into RegEdit, create your key under HKLM\Wow6432Node\Software instead.
  • If you're creating the Registry key from an installer, use a 32-bit installer. Then it will write to what it sees as HKLM\Software, which is really HKLM\Wow6432Node\Software.
  • Change your project options to target "Any Platform" (in Project Options > Build tab). Make sure to set it for both debug and release.
Joe White
Your psychic powers are better than mine...impressive.
Steve Danner
Your psychic debugging powers was spot on!
Jason94