Home Backend Development C++ Why Can't My 32-bit Application Access the 64-bit Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall?

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 PM

Why Can't My 32-bit Application Access the 64-bit Registry Key HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall?

Unable 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);
}
Copy after login

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
}
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

C language function format letter case conversion steps C language function format letter case conversion steps Mar 03, 2025 pm 05:53 PM

C language function format letter case conversion steps

Gulc: C library built from scratch Gulc: C library built from scratch Mar 03, 2025 pm 05:46 PM

Gulc: C library built from scratch

What are the types of values ​​returned by c language functions? What determines the return value? What are the types of values ​​returned by c language functions? What determines the return value? Mar 03, 2025 pm 05:52 PM

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 What are the definitions and calling rules of c language functions and what are the Mar 03, 2025 pm 05:53 PM

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

How does the C   Standard Template Library (STL) work? How does the C Standard Template Library (STL) work? Mar 12, 2025 pm 04:50 PM

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

Where is the return value of the c language function stored in memory? Where is the return value of the c language function stored in memory? Mar 03, 2025 pm 05:51 PM

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

distinct usage and phrase sharing distinct usage and phrase sharing Mar 03, 2025 pm 05:51 PM

distinct usage and phrase sharing

How do I use algorithms from the STL (sort, find, transform, etc.) efficiently? How do I use algorithms from the STL (sort, find, transform, etc.) efficiently? Mar 12, 2025 pm 04:52 PM

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

See all articles