Csharp/C#教程:SetValue 64位机器注册表分享


SetValue 64位机器注册表

我想在下面的注册表路径中为’NoModify’设置一个值。 “HKEY_LOCAL_MACHINE SOFTWARE 微软的Windows CurrentVersion 卸载 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(@"SOFTWAREMicrosoftWindowsCurrentVersionUninstall{xxxx}", true); //SL: Key Name if (noModifyKey != null) { noModifyKey.SetValue("NoModify", 0); noModifyKey.Flush(); } } 

当您使用64位计算机并且您的应用程序是32位时 – 它应该将这些设置存储在HKLM Software WOW6432Node而不是HKLM Software 节点中。

至于您将.NET程序编译为x86而不是AnyCPU ,您将在任何情况下使用适用于x86的“正确”注册表项,因为它将作为x86运行。

如果你把它编译成x64AnyCPU ,它可能会非常棘手,因为它可能在x64机器上以x64运行并使用“错误”的注册表,其中HKLMSOFTWARE for x86程序实际上是 HKLMSOFTWAREWOW6432Node

这是我在代码中的错误。

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

应如下:

上述就是C#学习教程:SetValue 64位机器注册表分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

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

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1007684.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐