getting a registry key and value in C#
<p>Sorry if this is simple, I haven't coded since college. I'm trying to write a program to view registry entries in Windows 7. I want to check to see if the registry value exists first, then check to see what the value is. If it doesn't exist, I want one message, if it does exist, I want one message reflecting a value of 1, and another reflecting a value of 0. I got the code to work if the registry key doesn't exist, but if I add the key and value it crashes. Not sure what I'm doing wrong here. Any suggestions would be appreciated. Here is my code.</p>

<pre><code>using (RegistryKey Key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\services\LanmanServer\Parameters"))
if (Key != null)
{
    string val = (string)Key.GetValue("EnableOplocks");
    if (val == null)
    {
        oplockTextBox.Text = "Not Present In Registry";
        oplockTextBox.BackColor = Color.Yellow;
    }
    else if (val == "1")
    {
        opslockTextBox.Text = "NO";
        opslockTextBox.BackColor = Color.Red;
    }
    else
    {
        oplockTextBox.Text = "YES";
        oplockTextBox.BackColor = Color.Green;
    }
}
else
{
    MessageBox.Show("");
}
</code></pre>
