PnP
PnP

Reputation: 3185

Registry Key Get Value returns NULL

Why does the following code return 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;

I do have Administrator privileges.

Upvotes: 1

Views: 2591

Answers (1)

Orestis P.
Orestis P.

Reputation: 825

You are actually getting this subkey "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell". This is because some keys are redirected by WOW64. Check this for more info.

Try the following:

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;

Upvotes: 3

Related Questions