从 32 位应用程序读取 64 位注册表 [英] Reading 64bit Registry from a 32bit application
问题描述
我有一个为 AnyCPU 编译的 c# 单元测试项目.我们的构建服务器是 64 位机器,并安装了 64 位 SQL Express 实例.
测试项目使用类似于以下的代码来识别 .MDF 文件的路径:
私有字符串 GetExpressPath(){RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey(@SOFTWAREMicrosoftMicrosoft SQL ServerInstance NamesSQL");string sqlExpressKeyName = (string) sqlServerKey.GetValue(SQLEXPRESS");RegistryKey sqlInstanceSetupKey = sqlServerKey.OpenSubKey( sqlExpressKeyName + @Setup");返回 sqlInstanceSetupKey.GetValue(SQLDataRoot").ToString();}
这段代码在我们的 32 位工作站上运行良好,并且在构建服务器上运行正常,直到我最近使用 NCover 启用了代码覆盖率分析.由于 NCover 使用 32 位 COM 组件,因此测试运行程序 (Gallio) 作为 32 位进程运行.
检查注册表,没有实例名称";下键
<块引用>HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftMicrosoft SQL Server
有没有办法让运行在 32 位模式下的应用程序访问 Wow6432Node 之外的注册表?
您必须在创建/打开注册表项时使用 KEY_WOW64_64KEY 参数.但是 AFAIK 不能使用 Registry 类,而只能在直接使用 API 时.
这可能有助于您入门.>
I have a c# unit test project that is compiled for AnyCPU. Our build server is a 64bit machine, and has a 64bit SQL Express instance installed.
The test project uses code similar to the following to identify the path to the .MDF files:
private string GetExpressPath()
{
RegistryKey sqlServerKey = Registry.LocalMachine.OpenSubKey( @"SOFTWAREMicrosoftMicrosoft SQL ServerInstance NamesSQL" );
string sqlExpressKeyName = (string) sqlServerKey.GetValue( "SQLEXPRESS" );
RegistryKey sqlInstanceSetupKey = sqlServerKey.OpenSubKey( sqlExpressKeyName + @"Setup" );
return sqlInstanceSetupKey.GetValue( "SQLDataRoot" ).ToString();
}
This code works fine on our 32bit workstations, and did work ok on the build server until I recently enabled code coverage analysis with NCover. Because NCover uses a 32bit COM component, the test runner (Gallio) runs as a 32bit process.
Checking the registry, there is no "Instance Names" key under
HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftMicrosoft SQL Server
Is there a way for an application running in 32bit mode to access the registry outside Wow6432Node?
you have to use the KEY_WOW64_64KEY param when creating/opening the registry key. But AFAIK that's not possible with the Registry class but only when using the API directly.
This might help to get you started.
这篇关于从 32 位应用程序读取 64 位注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!