问题描述
可能重复:
C#WOW6432注册表节点messin东西
这是在code:
var b1 = Registry.LocalMachine.OpenSubKey("software", true);
var b2 = Registry.LocalMachine.OpenSubKey("software", true).OpenSubKey("company");
var r1 = Registry.LocalMachine.OpenSubKey("software").OpenSubKey("company").GetValueNames();
string resultString = Registry.LocalMachine.OpenSubKey("Software", true).CreateSubKey("company").GetValue(name).ToString();
我用名称
= ApplicationDirectory
调用它。在最后一行,前两个变量指向(根据其名称
属性)的正确位置。问题是与 R1
,其中没有列出 HKEY_LOCAL_MACHINE \ SOFTWARE \公司
的内容,而是 HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \公司
。为什么是这样?这是在64位机器上的一些重定向?
I invoke it with name
= "ApplicationDirectory"
. At the last line, the first two variables point to the correct locations (based on their Name
property). The problem is with r1
, which doesn't list the contents of HKEY_LOCAL_MACHINE\SOFTWARE\company
, but rather HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\company
. Why is this? Is this some redirection in 64-bit machines?
推荐答案
是的,有一个重定向在64位机32位应用程序。看评论就你的问题,同时也这太回答。
Yes, there is a redirection for 32-bit applications on 64-bit machines. See comments on your question, and also this SO answer.
如果你面向.NET 4或以上,你就可以同时访问 Wow6432Node
(用于32位应用程序)和标准节点(一用于64位应用程序)为 RegistryKey.OpenBaseKey 一>方法提供类型 RegistryView 允许的参数选择正确的节点使用。
If you target .Net 4 or above, you'll be able to access both Wow6432Node
(used for 32-bit applications) and "standard" node (the one used for 64-bit applications) as RegistryKey.OpenBaseKey method provides a parameter of type RegistryView that allows choosing the correct node to use.
如果您正在使用.net 3.5或previous版本,那么你就必须使用的P / Invoke,如果你希望能够在64位计算机上读取两个32/64位注册表项。你将不得不使用 RegOpenKeyEx的并指定 KEY_WOW64_32KEY
作为标志所需的访问。但是,这又是一个故事,你的问题的范围。
If you're using .Net 3.5 or previous version, then you'll have to use P/Invoke if you want to be able to read both 32/64 bit registry keys on a 64-bit machine. You'll have to use RegOpenKeyEx and specify KEY_WOW64_32KEY
as flag for desired access. But this is another story and out of the scope of your question.
这篇关于读取注册表时怪异的行为在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!