registry editing: NullReferenceException driving m
Hello,
I'm absolutely new to programming, so please don't be too hard on me...
I'm trying to make a simple form application to hide or show hidden files. When I try to run the application I get a "System.NullReferenceException: Object reference not set to an instance of an object."
I found many topics related to this problem, but I still cannot figure it out.
Here's the code:
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void HideFiles()
{
RegistryKey MyKey = Registry.CurrentUser;
MyKey = MyKey.OpenSubKey(".Software\\Microsoft\\Windows\\C urrentVersion\\Explorer\\Advanced", true);
MyKey.SetValue("Hidden",2);
MyKey.Close();
}
private void ShowFiles()
{
RegistryKey MyKey;
MyKey = Registry.CurrentUser;
MyKey = MyKey.OpenSubKey(".Software\\Microsoft\\Windows\\C urrentVersion\\Explorer\\Advanced", true);
MyKey.SetValue("Hidden",1);
MyKey.Close();
}
private void ShowButton_Click(object sender, EventArgs e)
{
ShowFiles();
}
private void HideButton_Click(object sender, EventArgs e)
{
HideFiles();
}
}
|