Re: Registry.LocalMachine.OpenSubKey(...) is returning NULL

"thephatp" wrote:

On Mar 27, 9:36 pm, "Steve Gerrard" <mynameh...@xxxxxxxxxxx> wrote:
thephatp wrote:
This is incredibly strange. I used regedit and went to
HKEY_LOCAL_MACHINE and create a new subkey under "Software". I added
a few more, then went into code to try to read them. I kept getting
null returned when I tried to open them, so I decided to try this:


The results where dumbfounding--they did NOT match what I see in the
Registry under HKEY_LOCAL_MACHINE. The list values returned from the
Registry.LocalMachine.GetSubKeyNames() method is MUCH longer than the
list of subkeys that exist in the registry.

What gives? (I'm really hoping this is an easy explanation for
someone, but I'm just not getting it.)

Vista, by chance?

If so, you may want to look up Registry
Virtualization... Hide quoted text -

- Show quoted text -

Yes, of course. :(

That is SO LAME. Does this mean that I need to set app settings for
ALL users at install? What happens when a new user is created? I
need to edit the registry and create some default app settings, and I
obviously want these defaults to apply to all users.

If it's in the article, forgive me. I'm planning on reading it

But even at a glance, I saw the big difference (redirect to users
location). :(

Thanks for the link!


Be aware that registry virtualization not only occurs in Vista, but with 64
bit OS such as XP.

Regarding user settings, they should be stored under the HKEY_CURRENT_USER
path. If the user's settings are not found when the code is launched (such
as a new user is added to the computer), then copy from the safe place such
as HKEY_LOCAL_MACHINE. This way you are only reading from HKLM. Hopefully I
understood your concern correctly.