SetValue 64位机器注册表

ABC*_*BCD 5 .net c# registry installation 64-bit

我想在下面的注册表路径中设置“NoModify”的值。“HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\XXXX”

我使用下面的代码,它仅适用于 X86 机器。您能看出这对于 x64 机器不起作用的任何原因吗?

// This value is correct
RegistryView registryView = releaseFlags.Contains("PLATFORM_X86") ? RegistryView.Registry64 : RegistryView.Registry32;

    using (RegistryKey hkeyLocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
    {
        RegistryKey noModifyKey = hkeyLocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{xxxx}", true); //SL: Key Name

        if (noModifyKey != null)
        {
            noModifyKey.SetValue("NoModify", 0);
            noModifyKey.Flush();
        }
    }
Run Code Online (Sandbox Code Playgroud)

ABC*_*BCD 1

这是我的代码错误。

RegistryView registryView = releaseFlags.Contains("PLATFORM_X86") ? RegistryView.Registry64 : RegistryView.Registry32;
Run Code Online (Sandbox Code Playgroud)

应如下所示:

RegistryView registryView = releaseFlags.Contains("PLATFORM_X86") ? RegistryView.Registry32 : RegistryView.Registry64;
Run Code Online (Sandbox Code Playgroud)