当我试图为注册表键设置值时,我会收到一个NullReference Exception异常。以下是我的代码。有没有人知道为什么?
using System;
using Microsoft.Win32;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
RegistryKey myKey = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\Current Version\Policies\System", true);
myKey.SetValue("DisableTaskMgr", 0, RegistryValueKind.DWord);
}
}
}