C#读取注册表:产品ID返回空值在86针对性的应用程序。 "任何CPU"工作正常 [英] C# Reading the registry: ProductID returns null in x86 targeted app. "Any CPU" works fine
问题描述
我最近b我的项目设置为on 任何CPU
运行移动到W7 64位机VS 2010 $ B $。当我将其更改为在 86
有针对性,我注意到我的一些注册表的要求不再起作用。
I have recently moved to a W7 64bit machine with VS 2010.
My project is set to run on Any CPU
. When I change this to be targeted at x86
I noticed some of my registry calls no longer work.
我尝试读取的ProductID
字段,像这样:
I am trying to read the ProductID
field like so:
RegistryKey windowsNTKey = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion");
object productID = windowsNTKey.GetValue("ProductId");
的productID
总是空<在x86的模式下运行时,在运行时/ code>任何CPU它工作正常。这到底是怎么回事呢?
productID
is always null
when running in x86 mode, when running in "Any CPU" it works correctly. What is going on here?
推荐答案
某些注册表项被重定向WOW64。关于该主题的更多信息可在MSDN上
的http:// msdn.microsoft.com/en-us/library/aa384232(v=vs.85).aspx
Some registry keys are redirected by WOW64. More information on this topic is available on MSDN http://msdn.microsoft.com/en-us/library/aa384232(v=vs.85).aspx
如果你真的想始终可以访问64位节点(.NET4):
If you really want to always access the x64 node (.Net4) :
RegistryKey localMachine = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
RegistryKey windowsNTKey = localMachine.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion");
object productID = windowsNTKey.GetValue("ProductId");
这篇关于C#读取注册表:产品ID返回空值在86针对性的应用程序。 "任何CPU"工作正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!