Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I added a registry key, but I cannot find it programmatically

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

HKLM\Software\Foo\Bar

Bar has a k/v pair of "wtf"/"idk". I verified that these changes "took" by closing regedit and re-opening it. Hey, they're still there! Swell.

RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Foo\Bar");

if (key != null)
{
    var = key.GetValue("wtf").ToString();
}

The problem is, key is null.

When. . .

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

Is called, Foo doesn't show up amongst the however many SubKeyNames.

So, I am obviously missing something stupid. What specifically am I missing?

like image 558
peacedog Avatar asked Sep 09 '11 15:09

peacedog


People also ask

Where do I find Hkey_current_user software?

The supporting files for HKEY_CURRENT_USER are in the %SystemRoot%\Profiles\Username folder.


2 Answers

If you are running a 32 bit process on a 64 bit version of Windows the 32 bit process (your test application) is not always able to see the keys you created using 64 bit regedit.

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

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

like image 176
Martin Liversage Avatar answered Sep 22 '22 02:09

Martin Liversage


Might be a x64 issue? When reading from the registry in a x86 process you are redirected to the Software\Wow6432node.

like image 20
riezebosch Avatar answered Sep 26 '22 02:09

riezebosch