Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

.net - Why is OpenSubKey() returning null on my Windows 7 64-bit system?

Do OpenSubKey() and other Microsoft.Win32 registry functions return null on 64-bit systems when 32-bit registry keys are under Wow6432node in the registry?

I'm working on a unit testing framework that makes a call to OpenSubKey() from the .NET library.

My development system is a Windows 7 64-bit environment with Visual Studio 2008 SP1 and the Windows 7 SDK installed.

The application we're unit testing is a 32-bit application, so the registry is virtualized under HKLMSoftwareWow6432node. When we call:

Registry.LocalMachine.OpenSubKey( @"SoftwareMyCompanyMyApp" );

Null is returned, however explicitly stating to look here works:

Registry.LocalMachine.OpenSubKey( @"SoftwareWow6432nodeMyCompanyMyApp" );

From what I understand this function should be agnostic to 32-bit or 64-bit environments and should know to jump to the virtual node.

Even stranger is the fact that the exact same call inside a compiled and installed version of our application is running just fine on the same system and is getting the registry keys necessary to run; which are also being placed in HKLMSoftwareWow6432node.

What should I do?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

It sounds like your unit testing project compiles to 64 bit. In the Compile settings of your unit testing project, set the "Target CPU" to x86 (instead of AnyCPU).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...