简体   繁体   English

Registry API 32 vs 64bit,以及VS2010设置

[英]Registry API 32 vs 64bit, and VS2010 setup

We have a .net 4.0 app which uses a couple of registry keys and a vs2010 setup & deployment project which creates those keys @ setup 我们有一个使用几个注册表项的.net 4.0应用程序,以及一个在安装程序中创建这些项的vs2010安装和部署项目

Problem - (default) RegEdit shows the keys exist but the .net code returns null on OpenSubKey with the correct path ( incl. the \\ ) 问题-(默认)RegEdit显示键存在,但.net代码在OpenSubKey上使用正确的路径(包括\\)返回null

Which as it turns out is due to 32 & 64 bit registries per KB305097 事实证明,这是由于每个KB305097的 32和64位注册表

and which requires code such as 并且需要诸如

RegistryKey someFunc()
{
    var r64o32 = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, 
                Environment.Is64BitOperatingSystem  ? RegistryView.Registry64 :    
           RegistryView.Registry32);

    return r64o32.OpenSubKey(regKey);
}

However i cannot test the code above as I don't have a 32bit machine available but the app needs to be available on 32bit machines as well 但是我无法测试上面的代码,因为我没有可用的32位计算机,但是该应用程序也需要在32位计算机上可用

so looking for help on - 所以寻求帮助-

  1. is the approach above correct for both 64/32bit ? 上面的方法对64 / 32bit都正确吗?
  2. does the setup created by vs2010 setup project install the defined registry entry on 64/32 registry based on the the machine ? vs2010安装程序项目创建的安装程序是否根据计算机在64/32注册表上安装了定义的注册表项?
  3. Any other gotchas ? 还有其他陷阱吗?

You don't need to do special casing on the RegistryView as you are using OpenBaseKey this is asking for a specific view of the Registry regardless of how you compiled your application 使用OpenBaseKey ,不需要在RegistryView上做特殊的大小写,这是在询问注册表的特定视图,而不管您如何编译应用程序

RegistryKey r = Microsoft.Win32.RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, 
                                                        RegistryView.Registry64);

Also remember that if you are on a 32bit machine, then OpenBaseKey will just fallback to Registry32 还请记住,如果您使用的是32位计算机,则OpenBaseKey将仅回退到Registry32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用VS2010注册表编辑器创建针对64位操作系统的自定义注册表项“Programmable” - How to create custom registry key 'Programmable' targeted on 64bit OS with VS2010 registry editor vs2013 64bit中的AccessViolation异常不是vs2010 64bit中的 - AccessViolation Exception in vs2013 64bit not vs2010 64bit 如何在vs2010中为64位版本的办公室开发Microsoft office word addin - How to develop Microsoft office word addin for 64bit version office in vs2010 在64位计算机上的VS2010中通过VLC播放RTSP - Play RTSP through VLC in VS2010 on 64bit machine 广汽 32 位与 64 位 - GAC 32bit vs. 64bit VS2010成功加载了SOS.dll,但在我的64位OS上无法使用其他命令 - VS2010 loaded SOS.dll successfully but other commands can't be used on my 64bit OS C#Windows程序将文件写入“ sysWOW64”和“程序文件(x86)”。 使用VS安装项目。 64位系统上的32位应用程序 - C# Windows Program writes files to “sysWOW64” and to “Program Files(x86)”. Using VS Setup Projects. 32bit App on 64bit System C#32位应用程序64位注册表 - C# 32bit app 64bit registry 从 32 位应用程序读取 64 位注册表 - Reading 64bit Registry from a 32bit application 安装程序与 2010 64 位更改平台 - setup installer vs 2010 64 bit changed platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM