SetValue 64bit machine registry

前端 未结 4 971
忘掉有多难
忘掉有多难 2021-01-14 01:03

I want to set a value for \'NoModify\' in below registry path. \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\XXXX\"

I am using below

相关标签:
4条回答
  • 2021-01-14 01:21

    As far as you compiles your .NET program as x86 not AnyCPU, you will be using the "correct" registry keys meant for x86 in any circumstances because it will be running as x86.

    If you compile it as x64 or AnyCPU, it could be quite tricky because it will probably run as x64 on an x64 machine and uses the "wrong" registry where HKLM\SOFTWARE for x86 programs is actually HKLM\SOFTWARE\WOW6432Node.

    0 讨论(0)
  • 2021-01-14 01:29

    You should open base key in this way.
    It works for me.

    var rk = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry32);
        if (Environment.Is64BitOperatingSystem) {
            rk = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);
            var val = rk.OpenSubKey("SOFTWARE\\Pourab\\sanjande", true);
        
            val.SetValue("test", "testvalue");
        }
    
    0 讨论(0)
  • It's my mistake in the code.

    RegistryView registryView = releaseFlags.Contains("PLATFORM_X86") ? RegistryView.Registry64 : RegistryView.Registry32;
    

    Should be as follows:

    RegistryView registryView = releaseFlags.Contains("PLATFORM_X86") ? RegistryView.Registry32 : RegistryView.Registry64;
    
    0 讨论(0)
  • 2021-01-14 01:39

    When you are on a 64 bit machine and your app is 32 bit - it should store these settings in the HKLM\Software\WOW6432Node instead of the HKLM\Software\ node.

    0 讨论(0)
提交回复
热议问题