I have added a registry key but cannot find it programmatically

So, I used RegEdit to add the following to the registry of my workstation:

HKLM \ Software \ Foo \ Bar

The bar has a pair k / v "wtf" / "idk". I confirmed that these changes were "accepted" by closing regedit and reopening it. Hey, they are still there! Swell

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Foo\Bar"); if (key != null) { var = key.GetValue("wtf").ToString(); } 

The problem is that the key is null.

When.,.

 Registry.LocalMachine.OpenSubKey("Software").GetSubKeyNames() 

Called, Foo is not displayed among the many SubKeyNames.

So, I obviously miss something stupid. What exactly am I missing?

+5
c # registry
source share
3 answers

If you are running a 32-bit process on a 64-bit version of Windows, the 32-bit process (your test application) cannot always see the keys you created using 64-bit regedit.

Try to run the application as 64 bit or use regedit to open the key using the path HKLM\SOFTWARE\Wow6432Node\Foo\Bar .

You can learn more about 32-bit and 64-bit application data in the registry on MSDN.

+10
source share

Maybe there is an x64 problem? When reading from the registry during the x86 process, you are redirected to Software \ Wow6432node.

+4
source share

Try to open it for reading only Registry.LocalMachine.OpenSubKey("Software", false).GetSubKeyNames() Perhaps you get only those with which you can write.

+1
source share

All Articles