


Why Can't My 32-bit Application Access the 64-bit Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall?
Jan 05, 2025 pm 04:19 PMUnable to Open Registry Key in OpenSubKey()
When attempting to retrieve display names for subkeys within the registry key HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall, using the code:
RegistryKey newKey; string val; string KeyPath64Bit = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; RegistryKey mainKey = Registry.LocalMachine.OpenSubKey(KeyPath64Bit); string[] RegKeys64Bits = Registry.LocalMachine.OpenSubKey(KeyPath64Bit).GetSubKeyNames(); foreach (string s in RegKeys64Bits) { newKey = mainKey.OpenSubKey(s); val = newKey.GetValue("DisplayName", -1, RegistryValueOptions.None).ToString(); if (val != "-1") file64.WriteLine(val); }
One specific subkey, {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}, remains elusive. Instead, GetSubKeyNames() returns {DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}.KB2151757, a subkey that lacks a display name.
Cause:
On a 64-bit operating system, a 32-bit application by default accesses the HKLMSoftwareWow6432Node registry key. To retrieve the 64-bit version of the key containing the desired subkey, you need to specify RegistryView.Registry64.
Solution:
In .NET 4.0 and above, you can open the 64-bit registry key using the RegistryView property:
using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) using (var key = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall")) { // key now points to the 64-bit key }
For .NET 3.5, you can utilize P/Invoke to access 64-bit keys. Refer to the documentation at the following link for detailed instructions:
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 Why Can't My 32-bit Application Access the 64-bit Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall?. For more information, please follow other related articles on the PHP Chinese website!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

C language function format letter case conversion steps

What are the types of values returned by c language functions? What determines the return value?

What are the definitions and calling rules of c language functions and what are the

How does the C Standard Template Library (STL) work?

Where is the return value of the c language function stored in memory?

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently?
