注册表访问.net 2.0和.net 4.0之间的差异 [英] Registry access differences between .net 2.0 and .net 4.0

查看:108
本文介绍了注册表访问.net 2.0和.net 4.0之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用带有.net 2.0的visual studio 2005,用c#编程。我创建了一个32位应用程序,运行精细的32位计算机和64位计算机。相同的代码也可以在XP和窗口7上正常运行。在64位计算机上,相同的代码访问本机和wow64注册表,并且编写这样的代码,以便64位应用程序的端口不需要对代码进行任何更改。注册表访问代码(虽然我从未编写过64位应用程序来测试它)。我的目标是将此应用程序的开发移植到visual studio 2010,并以.net 4.0为目标,并创建应用程序的32位和64位版本。我需要知道.net 2.0和.net 4.0之间是否存在关于如何访问本机和wow64注册表的区别。在.net 2.0下,本应用程序使用advapi32.dll导入,例如RegCreateKeyEx以及WOW64_32Key和WOW64_64Key标志来执行此操作。对于32位和64位应用程序,.net 4.0是否提供或要求使用不同的方法来访问64位计算机上的两个注册表?

谢谢,

Phil

I have been using visual studio 2005 with .net 2.0, programming in c#. I have created a 32-bit app which is runing fine 32-bit machines and 64-bit machines. The same code also runs fine on both XP and window 7. On 64-bit machines the same code accesses both the native and wow64 registries, and is written so that a port to a 64-bit application would not require any code changes to the registry access code (although I have never written a 64-bit app yet to test this out). My aim is to port development of this application to visual studio 2010, and targeting .net 4.0, and creating both 32-bit and 64-bit versions of the app. I need to know if there are differences between .net 2.0 and .net 4.0 with regard to how both the native and wow64 registries are accessed. Under .net 2.0, the present app uses advapi32.dll imports such as RegCreateKeyEx in conjunction with the WOW64_32Key and WOW64_64Key flags to do this. Does .net 4.0 provide or require different means to acess both registries on a 64-bit machine, for both 32-bit and 64-bit applications?
Thanks,
Phil

推荐答案

看起来32位应用程序访问32位注册表,而64位应用程序访问64位注册表。 Registry Redirector通过在WOW64上提供注册表某些部分的单独逻辑视图来隔离32位和64位应用程序。



.NET Framework的Microsoft.Win32命名空间提供了与注册表一起使用的方法。



我在帮助文件中找到了一些可以帮助您进行研究和开发测试程序的项目。所有这些都是通过Visual Studio 2012帮助文件访问的。



受WOW64影响的注册表项 [ ^ ]



WOW64上的注册表重定向示例 [ ^ ]



注册表重定向器(Windows) [ ^ ]



访问备用注册表视图 [ ^ ]



使用Microsoft.Win32命名空间(Visual Basic)读取和写入注册表 [ ^ ]



Microsoft.Win32命名空间 [ ^ ]
It looks like 32-bit applications access the 32-bit Registry and 64-bit applications access the 64-bit Registry. The Registry Redirector isolates 32-bit and 64-bit applications by providing separate logical views of certain portions of the registry on WOW64.

The Microsoft.Win32 Namespace of the .NET Framework provides methods to work with the Registry.

I found some items in the help file that may help you to do the research and develop a test program. All of these were accessed via the Visual Studio 2012 Help file.

Registry Keys Affected by WOW64[^]

Example of Registry Redirection on WOW64[^]

Registry Redirector (Windows)[^]

Accessing an Alternate Registry View[^]

Reading from and Writing to the Registry Using the Microsoft.Win32 Namespace (Visual Basic)[^]

Microsoft.Win32 Namespace[^]


如果我没记错目标.Net版本4.0,可以使用 OpenBaseKey 函数,如下所示:

If I remember correctly for target .Net version 4.0, one can use OpenBaseKey function like below:
RegistryKey registryKeyA;
if (Environment.Is64BitOperatingSystem)
{
    registryKeyA = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
    registryKeyA = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
}



参考: MSDN:RegistryKey.OpenBaseKey方法 [ ^ ]


这篇关于注册表访问.net 2.0和.net 4.0之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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