Registry.SetValue does not work for x86

I want to edit a specific value (type REG_SZ) in the registry for both x64 and x86, but the SetValue method will not change the value for x86. X64 works great. 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 use the parameter RegistryView.Registry32in the first line of code to change the value in the x86 registry, but this does not work.

The problem has been identified but not resolved. This code always changes the key in the x64 registry (WOW6432Node):

"SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FolderDescriptions\\{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}\\PropertyBag"
+4
source share
1 answer

You obviously have a program running in x86 mode (32-bit). Windows x64 performs registry redirection for 32-bit applications, so trying to access

SOFTWARE\Microsoft

SOFTWARE\WOW6432Node\Microsoft

Registry32 .NET, x64. , .

SOFTWARE\Microsoft 64- 32- , Registry64, .

( )

  • SOFTWARE\ - , 64- 64-

  • SOFTWARE\WOW6432Node\ - 32- 64-

WOW64 - , 64- . , 32- , 64-. "() Windows (32) Windows64".

+10

Source: https://habr.com/ru/post/1648156/


All Articles