注册表项获取值返回 NULL

本文关键字:返回 NULL 获取 注册表 | 更新日期: 2023-09-27 18:32:18

为什么下面的代码返回 NULL for shellValue

        string shellValue;
        RegistryKey shellKey = Registry.LocalMachine;
        shellKey = shellKey.OpenSubKey(@"SOFTWARE'Microsoft'Windows NT'CurrentVersion'Winlogon", true);
        shellValue = shellKey.GetValue("Shell") as string;

我确实具有管理员权限。

注册表项获取值返回 NULL

您实际上得到了这个子项"HKEY_LOCAL_MACHINE''SOFTWARE''Wow6432Node''Microsoft''Windows NT''CurrentVersion''Winlogon''Shell"。 这是因为某些键由 WOW64 重定向。 查看此内容以获取更多信息。

请尝试以下操作:

string shellValue;
RegistryKey shellKey = RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, RegistryView.Registry64);;
shellKey = shellKey.OpenSubKey(@"SOFTWARE'Microsoft'Windows NT'CurrentVersion'Winlogon", true);
shellValue = shellKey.GetValue("Shell") as string;