"Object reference not set to an instance of an object."

Posted by: Slyce

"Object reference not set to an instance of an object." - 02/19/07 06:47 PM

I'm trying to a part in my program to enable CMD when it has been disabled.
The registry value is thus:

> Path "HKCU\Software\Policies\Microsoft\Windows\System"
> Key "Disable CMD"
> Value "0"


Every time I try to enable CMD with my program, I get an error message:

"Object reference not set to an instance of an object."

My code looks like this:

 Code:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If ComboBox1.Text = "Command Prompt" Then
            Dim regKey As RegistryKey = Registry.CurrentUser.OpenSubKey("Software\Policies\Microsoft\Windows\System", True)
            regKey.SetValue("DisableCMD", 0)
        End If
End Sub


Can anybody help me?

Thank you in advance!
~Slyce

EDIT: Nevermind, I got it. Turns out the key didn't exist, causing the compiler to freak out. Sorry everyone.