Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

c# - 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:

HKLMSoftwareFooBar

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(@"SOFTWAREFooBar");

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...