注册表项获取值返回NULL

时间:2013-09-21 12:33:37

标签: c#

为什么以下代码为shellValue返回NULL?

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

我有管理员权限。

1 个答案:

答案 0 :(得分:2)

您实际上正在获取此子项“HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Microsoft \ Windows NT \ CurrentVersion \ Winlogon \ Shell”。这是因为某些键被WOW64重定向。查看this了解详情。

尝试以下方法:

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;
相关问题