469,352 Members | 1,668 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

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

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:

Registry.LocalMachine.GetSubKeyNames()

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.)

Also, I'm having another, just as concerning problem. In both the
Registry and in code from the list returned by GetSubKeyNames, the
subkey "Microsoft" exists. However, notice the following:

RegistryKey key1 = Registry.LocalMachine.OpenSubKey( "Software" ); //
This returns the key -- Success
RegistryKey key2 = Registry.LocalMachine.OpenSubKey( "Software\
\Microsoft" ); // This returns NULL :(
RegistryKey key3 = key1.OpenSubKey( "Microsoft" ) ; // This also
returns NULL :(

Why could this be happening?

Thanks in advance!

Chad
Mar 28 '08 #1
3 23118
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:

Registry.LocalMachine.GetSubKeyNames()

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...http://msdn2.microsoft.com/en-us/library/aa965884.aspx
Mar 28 '08 #2
On Mar 27, 9:36*pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
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:
Registry.LocalMachine.GetSubKeyNames()
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...http://msdn2.microsoft.com/en-us/library/aa965884.aspx- 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
tomorrow.

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

Thanks for the link!

Chad
Mar 28 '08 #3


"thephatp" wrote:
On Mar 27, 9:36 pm, "Steve Gerrard" <mynameh...@comcast.netwrote:
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:
Registry.LocalMachine.GetSubKeyNames()
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...http://msdn2.microsoft.com/en-us/library/aa965884.aspx- 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
tomorrow.

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

Thanks for the link!

Chad
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.
Mar 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sara | last post: by
reply views Thread by George Durzi | last post: by
9 posts views Thread by Thomas Mlynarczyk | last post: by
1 post views Thread by =?Utf-8?B?SGFuIFFpYW8=?= | last post: by
1 post views Thread by sbowman | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.