Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 5th, 2005, 07:36 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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();
}


}
 
Old March 5th, 2005, 08:15 AM
Registered User
 
Join Date: Mar 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem solved!

There was a dot too many in the subkey registry string:
"Software\\...." i.s.o. ".Software\\..."







Similar Threads
Thread Thread Starter Forum Replies Last Post
This is driving me nuts... Klesk C# 3 January 27th, 2006 06:51 PM
Driving me mad - getting a div to display in IE elfranko HTML Code Clinic 0 December 21st, 2005 10:49 AM
Windows Registry Editing via Java Sandz J2EE 0 February 28th, 2005 10:05 AM
Layers driving me up the wall jaucourt Flash (all versions) 2 January 12th, 2005 10:20 AM
Driving me nuts! bhd8ball Classic ASP Professional 2 January 7th, 2005 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.