I added a registry key, but I cannot find it programmatically
Asked Answered
M

3

7

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?

Monogenetic answered 9/9, 2011 at 15:12 Comment(0)
S
15

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.

Strafford answered 9/9, 2011 at 15:16 Comment(1)
You and Reizebosch are correct; it's an x64 OS but the program is running as a 32bit app, and it was reading from Wow6432Node.Monogenetic
D
5

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

Dutiful answered 9/9, 2011 at 15:15 Comment(0)
T
1

Try to open it for read only Registry.LocalMachine.OpenSubKey("Software", false).GetSubKeyNames() probably you are getting only those you are able to write into.

Toft answered 9/9, 2011 at 15:21 Comment(1)
I didn't mention it in the question but the permissions were 5x5; I could write to the key.Monogenetic

© 2022 - 2024 — McMap. All rights reserved.