[英]Registry redirection does not happen for HKEY_CURRENT_USER
I have the following code: 我有以下代码:
RegistryKey objRegKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\MySettings\\Dwm\\Preferences", true);
I have a registry key present under: HKEY_CURRENT_USER\\SOFTWARE\\MySettings\\Dwm\\Preferences
and so this works fine. 我在以下位置存在注册表项: HKEY_CURRENT_USER\\SOFTWARE\\MySettings\\Dwm\\Preferences
,因此可以正常工作。
When I change the above code to read from local machine instead of current user: 当我更改以上代码以从本地计算机而不是当前用户读取时:
RegistryKey objRegKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\MySettings\\Dwm\\Preferences", true);
and create the following registry under: HKEY_LOCAL_MACHINE\\SOFTWARE\\MySettings\\Dwm\\Preferences
并在以下位置创建以下注册表: HKEY_LOCAL_MACHINE\\SOFTWARE\\MySettings\\Dwm\\Preferences
The code returns null. 该代码返回null。 I understand the reason being that due to registry redirection for 32 bit applications on a 64 bit OS, it tries to read the registry from: HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432NODE\\MySettings\\Dwm\\Preferences
and since the registry does not exists, it returns null. 我了解原因是由于对64位OS上的32位应用程序进行注册表重定向,因此它尝试从以下位置读取注册表: HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432NODE\\MySettings\\Dwm\\Preferences
并且由于注册表不存在,因此它返回null 。 The question is that why redirection only happens for HKEY_LOCAL_MACHINE
and not for HKEY_CURRENT_USER
? 问题是,为什么仅对HKEY_LOCAL_MACHINE
而不对HKEY_CURRENT_USER
进行重定向?
Registry Redirection isn't a binary option - either present or not. 注册表重定向不是一个二进制选项-是否存在。 Sometimes you want both 32-bit and 64-bit applications to have the same "view" of (part of) the registry and in other cases you do not. 有时,您希望 32位和64位应用程序对注册表(的一部分)具有相同的“视图”,而在其他情况下,则不需要。
That's why the specific keys affected by redirection are documented. 这就是为什么记录了受重定向影响的特定键的原因。 HKEY_CURRENT_USER
itself is shared, as is HKEY_CURRENT_USER\\Software
. HKEY_CURRENT_USER
本身是共享的, HKEY_CURRENT_USER\\Software
也是共享的。 However, HKEY_CURRENT_USER\\Software\\Classes\\CLSID
, which includes COM component registration data (which is necessarily 32/64 bit split) does perform redirection. 但是, HKEY_CURRENT_USER\\Software\\Classes\\CLSID
包含COM组件注册数据(必须进行32/64位拆分),它确实执行重定向。
Or, to put it another way, if registry redirection was universal, you wouldn't need all of this convolution involving Wow6432Node
, etc. You'd just have a 32-bit registry and a 64-bit registry. 或者,换句话说,如果注册表重定向是通用的,则不需要所有涉及Wow6432Node
等的卷积。您只需拥有32位注册表和64位注册表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.