且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用C#和“BUILD x86”进行注册表访问在64位机器上

更新时间:2023-02-14 19:57:52

你正在犯罪注册表重定向

***的解决方案是打开注册表的64位视图,如下所示:

The best solution is to open a 64 bit view of the registry, like this:

using Microsoft.Win32;
...
RegistryKey registryKey = 
    RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).
    OpenSubKey(@"Software\Microsoft\InetStp\Components");
object value = registryKey.GetValue(@"WMICompatibility");

如果您希望代码在32位和64位计算机上运行,​​那么您需要编码一些在注册表视图之间切换。

If you want your code to work on both 32 and 64 bit machines then you'll need to code some switching between registry views.

注意 :从32位进程访问64位视图的能力只是添加到.net 4中的.net库中。在此之前,您需要使用本机API,例如使用P / Invoke。

Note: The capability of accessing 64 bit views from 32 bit processes was only added to the .net libraries in .net 4. It seems that prior to that you needed to use native APIs, e.g. with P/Invoke.