[英]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 - 所以寻求帮助-
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.