Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted

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[^]
 
Share this answer
 
v2
If I remember correctly for target .Net version 4.0, one can use OpenBaseKey function like below:
C#
RegistryKey registryKeyA;
if (Environment.Is64BitOperatingSystem)
{
    registryKeyA = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
}
else
{
    registryKeyA = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
}

Refer: MSDN: RegistryKey.OpenBaseKey Method [^]
 
Share this answer
 
Comments
pjsr 21-Feb-13 12:48pm    
Thanks Sandeep. RegistryKey.OpenBaseKey is the way to go for .net 4 and after. Do you know if .net 4.0 can run on windows XP, and if RegistryKey.OpenBaseKey supported there too?
Phil
Sandeep Mewara 21-Feb-13 13:04pm    
I don't think .NET Framework 4.0 works with XP. (Similar discussion: http://stackoverflow.com/questions/4204194/is-net-4-0-compatible-with-windows-xp-sp2-or-below)
Mike Meinz 21-Feb-13 13:31pm    
.NET 4.0 Framework does work with XP. I have done it.
Sandeep Mewara 21-Feb-13 13:33pm    
Thanks for sharing the info. Looks like documentation are not updated.

Seems OP needs to try out what he needs on XP and see for himself if it works or not.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900