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

T

thephatp

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
 
T

thephatp

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
 
F

Family Tree Mike

thephatp said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top