为什么OpenSubKey()返回空在我的Windows 7 64位系统? [英] Why is OpenSubKey() returning null on my Windows 7 64-bit system?

查看:592
本文介绍了为什么OpenSubKey()返回空在我的Windows 7 64位系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

待办事项OpenSubKey()等的Microsoft.Win32注册表函数返回空值在64位系统上时,32位注册表项Wow6432node在注册表中?

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?

我工作的一个单元测试框架,使得从.NET库调用OpenSubKey()。

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

我的开发系统是Windows 与视觉&NBSP 7 64位环境;工作室  2008 SP1和Windows  7 SDK安装

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

我们的单元测试是一个32位应用程序,因此在注册表下的虚拟化的应用程序HKLM \ SOFTWARE \ Wow6432node 。当我们调用:

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

Registry.LocalMachine.OpenSubKey( @"Software\MyCompany\MyApp\" );

返回null,但明确说明要看看这里的工作:

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

Registry.LocalMachine.OpenSubKey( @"Software\Wow6432node\MyCompany\MyApp\" );

据我了解这个功能应该是不可知的32位或64位环境,应该知道,跳转到虚拟节点。

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.

更奇怪的是,我们的内部应用程序的编译和安装的版本完全相同的调用运行就好了同一个系统上,并越来越需要运行注册表项的事实;这也被放置在 HKLM \ SOFTWARE \ Wow6432node

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 HKLM\Software\Wow6432node.

我应该怎么办?

推荐答案

这听起来像您的单元测试项目编译为64位。在您的单元测试项目的编译设置,目标CPU设置为 86 ,而不是(值为anycpu )。

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

这篇关于为什么OpenSubKey()返回空在我的Windows 7 64位系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆