注册表项获取值返回NULL

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

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

我有管理员权限。

您实际上获得此子项“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;