64比特及在Windows 32位注册问题(在C#编程) [英] 64 bit & 32 bit Registry issue in Windows (Programming in c#)

查看:155
本文介绍了64比特及在Windows 32位注册问题(在C#编程)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Windows到我的软件的注册表中获得数据,但有一件事我遇到那就麻烦:

I'm trying to get data from the registry of windows to my software but there is one thing i'm having trouble with it:

如果我的软件运行在64位系统上的注册表路径将是:

if my software runs on a 64 bit system the registry path will be :

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\AVAST Software\Avast ProgramFolder

如果我的软件在32位系统上运行的注册表路径将是:

and if my software runs on 32 bit system the registry path will be :

HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast  ProgramFolder

我可以做什么?仔细检查每一次?

What can i do ? to double check every time ?

也许我会只选中第二个选项(不含 \Wow6432Node\ ),当软件在64位运行时,它会自动添加到路径的 \Wow6432Node\

maybe i will check only the second option(without the \Wow6432Node\) and when the software runs on 64 bit it will automatically add to the path the \Wow6432Node\ ?

什么是此问题的最佳解决方案?

What is the best solution for this issue ?

推荐答案

在你做其他事情,你应该有文档的很好看的注册表重定向。这是非常重要的,你有什么它做一个清醒的认识。

Before you do anything further, you should have a good read of the documentation of the registry redirector. It's really important that you have a clear understanding of what it does.

好了,现在您了解注册表重定向器,让我们来看看如何解决你的问题。你有几个选项。最简单的是建立自己的计划,目标86,并获得 HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder 不管你运行什么系统位数。这样,你的代码将始终处于32位进程中运行,因此总能看到注册表的32位视图。注册表重定向器将处理映射到真正的物理 Wow6432Node 透明。

OK, now that you understand the registry redirector, let's look at how to tackle your problem. You have a few options. The simplest is build your program to target x86, and access HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder no matter what bitness system you run on. That way your code will always run in a 32 bit process and so always see the 32 bit view of the registry. The registry redirector will handle the mapping onto the true physical Wow6432Node transparently.

另外,如果你必须使用值为anycpu ,且必须满足一个64位进程内运行,你需要使用的 RegistryView 枚举。这使您可以从注册表的32位视图阅读,即使从64位进程。但是,再次访问 HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder ,但却要求相对于注册表的32位认为关键。

Alternatively, if you must use AnyCPU, and must cater for running inside a 64 bit process, you need to use the RegistryView enumeration. This allows you to read from the 32 bit view of the registry, even from a 64 bit process. But again you access HKEY_LOCAL_MACHINE\SOFTWARE\AVAST Software\Avast ProgramFolder but ask for that key with respect to the 32 bit view of the registry.

注册表重定向是,你必须不硬代码 Wow6432Node 到您的路径。该文件说,它是这样的:

The golden rule with the registry redirector is that you must not hard code Wow6432Node into your paths. The documentation says it like this:

重定向键映射到Wow6432Node下的物理位置。例如,HKEY_LOCAL_MACHINE\Software被重定向到HKEY_LOCAL_MACHINE\Software\Wow6432Node。然而,重定向键的物理位置,应考虑由系统预留。应用程序不应直接访问一个关键的物理位置,因为这个位置可能会改变。

Redirected keys are mapped to physical locations under Wow6432Node. For example, HKEY_LOCAL_MACHINE\Software is redirected to HKEY_LOCAL_MACHINE\Software\Wow6432Node. However, the physical location of redirected keys should be considered reserved by the system. Applications should not access a key's physical location directly, because this location may change.

不要试图打破这一规则。该系统提供的机制从一个支持的方式32位认为阅读。

Don't be tempted to break that rule. The system provides mechanisms to read from the 32 bit view in a supported manner.

这篇关于64比特及在Windows 32位注册问题(在C#编程)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆