When a 32-bit application is running on a 64-bit Windows system, it can only access the registry key under HKEY_LOCAL_MACHINESoftwareWow6432Node. However, in some cases, access to the 64-bit registry is required.
Using .NET Framework 4.x and above:
.NET Framework 4.x and later provides the RegistryView enumeration, allowing direct access to 64-bit and 32-bit registry keys. Here’s how to do it:
Access 64-bit registry:
<code class="language-csharp">using Microsoft.Win32; RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); // 对64位注册表执行操作</code>
Access 32-bit registry:
<code class="language-csharp">RegistryKey localKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); // 对32位注册表执行操作</code>
For situations where you need to access both 64-bit and 32-bit registry keys, you can use the following method:
<code class="language-csharp">// 获取64位和32位节点的所有注册表值 var mergedValues = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).GetValues() .Concat(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).GetValues()); // 获取64位和32位节点的所有注册表项 var mergedKeys = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64).GetSubKeyNames() .Concat(RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).GetSubKeyNames());</code>
The above is the detailed content of How Can a 32-bit Application Access the 64-bit Windows Registry?. For more information, please follow other related articles on the PHP Chinese website!