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?
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.
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.
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.
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); }
The correct way would be to call the native registry api and passing the KEY_WOW64_32KEY
flag to RegOpenKeyEx/RegCreateKeyEx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With