C#无法读取键值名称

问题描述 投票:0回答:1

我正在尝试在C#中读取注册表中的所有子项它对于本机子键很有效,但是当我创建自己的键时,我无法读取它。

string all = "-start" + Environment.NewLine;
string registryKey2 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects\AnimateMinMax";
RegistryKey key2 = Registry.LocalMachine.OpenSubKey(registryKey2, true);

foreach (string valueName in key2.GetValueNames())
{
    all += valueName + Environment.NewLine;
}
all += "-End" + Environment.NewLine;
MessageBox.Show(all);

enter image description hereenter image description here

“测试” Dword键丢失

您有一些技巧吗?

最佳问候

c# registry
1个回答
1
投票

您正在查看错误的注册表项部分。您的应用程序被编译为32位,但是您的操作系统是64位。在这种情况下,Windows会自动重定向到注册表的WOW6432Node,其中注册表项不存在。

解决方案:

1)在项目设置中,将目标CPU更改为x64。

2)使用RegistryView.Registry64标志打开64位注册表视图。

var localMachine64 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
var key2 = localMachine64.OpenSubKey(registryKey2, true);
// rest of the code
© www.soinside.com 2019 - 2024. All rights reserved.