Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a WOW64 registry key from a 64-bit .NET application

My .NET application (any-CPU) needs to read a registry value created by a 32-bit program. On 64-bit Windows this goes under the Wow6432Node key in the registry. I have read that you shouldn't hard-code to the Wow6432Node, so what's the right way to access it with .NET?

like image 502
marijne Avatar asked Jul 02 '09 13:07

marijne


People also ask

How can I run 32-bit registry on 64-bit application?

To view or edit 64-bit keys, you must use the 64-bit version of Registry Editor (Regedit.exe). You can also view or edit 32-bit keys and values by using the 32-bit version of Registry Editor in the %systemroot%\Syswow64 folder.

Where is the WOW64 in registry?

Registry information on 32-bit applications running in WOW64 (Windows on Windows 64) mode is stored in the HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node registry branch.

What is Wow6432Node in Windows Registry?

The Wow6432 registry entry indicates that you're running a 64-bit version of Windows. The OS uses this key to present a separate view of HKEY_LOCAL_MACHINE\SOFTWARE for 32-bit applications that run on a 64-bit version of Windows.


2 Answers

If you can change the target .Net version to v4, then you can use the new OpenBaseKey function e.g.

RegistryKey registryKey; if (Environment.Is64BitOperatingSystem == true) {     registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64); } else {     registryKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32); } 
like image 152
woany Avatar answered Sep 23 '22 08:09

woany


The correct way would be to call the native registry api and passing the KEY_WOW64_32KEY flag to RegOpenKeyEx/RegCreateKeyEx

like image 28
Anders Avatar answered Sep 22 '22 08:09

Anders