Home >Backend Development >C++ >How Can a 32-bit Application Access 64-bit Registry Keys?
Accessing 64-bit Registry Keys from a 32-bit Application
When executing on a 64-bit OS, OpenSubKey() may fail to return a reference to a registry key that is visible in regedit.exe. This discrepancy arises because a 32-bit application defaults to inspecting the HKLMSoftwareWow6432Node branch instead of the desired branch.
To access the 64-bit version of the registry, explicitly specify the RegistryView parameter:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")) { // The key now points to the 64-bit subkey branch }
This technique ensures that the OpenSubKey() function targets the appropriate registry branch, providing access to the subkey of interest.
For .NET versions prior to 4.0, leveraging P/Invoke might be necessary to interact with 64-bit keys from a 32-bit application. A detailed guide on this approach can be found at: http://www.rhyous.com/2011/01/24/how-read-the-64-bit-registry-from-a-32-bit-application-or-vice-versa/
The above is the detailed content of How Can a 32-bit Application Access 64-bit Registry Keys?. For more information, please follow other related articles on the PHP Chinese website!