I want to edit a specific value (type REG_SZ
) in the registry for both, x64 and x86, but the SetValue method does not change the value for x86. The x64 works fine. This is my code:
RegistryKey regKeySpecific = RegistryKey.OpenBaseKey(
RegistryHive.LocalMachine, RegistryView.Registry32);
RegistryKey registryKey = regKeySpecific.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions\\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\\PropertyBag", true);
registryKey.SetValue("ThisPCPolicy", "Show", RegistryValueKind.String);
registryKey.Close();
I'm using the RegistryView.Registry32
parameter in the first code line to change the value in x86 registry, but this is not working.
The problem is identified, but not solved. This code changes always the key in the x64 (WOW6432Node) registry:
"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions\\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\\PropertyBag"
You evidently have a program executing in x86 (32-bit) mode. Windows x64 performs registry redirection for 32-bit applications, so that trying to access
SOFTWARE\Microsoft
will instead access
SOFTWARE\WOW6432Node\Microsoft
The Registry32
flag makes this same redirection available to .NET applications running as x64. It has no effect for you, because the OS already turned on that redirection.
To access SOFTWARE\Microsoft
on a 64-bit OS from a 32-bit process, you should use the Registry64
flag which disables the redirection.
Remember (your question has this backwards)
SOFTWARE\
is the native registry, 64-bit on a 64-bit OS
SOFTWARE\WOW6432Node\
is the 32-bit compatibility registry on a 64-bit OS
WOW64 is not the layer that provides 64-bit support. It is the layer that provides 32-bit application support when the OS is 64-bit. It means "(Support for) Windows (32) On Windows64".
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