2013-09-21 78 views
0

爲什麼下面的代碼返回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; 

我確實擁有管理員權限。

+0

正常工作對我來說,檢查鍵/值是否存在使用'regedit.exe' –

+0

它確實存在,在Windows中默認值是Explorer.exe的 – PnP

回答

1

你實際上得到這個子項「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; 
+0

我怎樣才能使它爲每個相應的操作系統做正確的密鑰? – PnP