我想從註冊表中讀取並設置一些值,但我不斷收到NullReferenceExceptions。NullReferenceException在RegistryKey
public partial class Form1 : Form
{
RegistryKey rkApp = null;
RegistryKey settings = null;
public Form1()
{
InitializeComponent();
rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
settings = Registry.CurrentUser.OpenSubKey("HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Shit", true);
if (settings.GetValue("automove") != null)
{
automove = true;
autostartToolStripMenuItem.Checked = true;
}
}
}
我在這個例子中刪除了一些不相關的代碼,但這是我的代碼...任何想法?
錯誤出現在行,如果(settings.GetValue("automove") != null)
是個例外,從拋出什麼線(檢查從異常'StackTrace') –
如果(settings.GetValue( 「汽車移動」)!= NULL) – Styler2go
是設置空? –