dustock
asked on
Display registry value
I am trying to display the value of DefaultPassword from HKEY_LOCAL_MACHINE\SOFTWAR E\Microsof t\Windows NT\CurrentVersion\Winlogon but when ever I try I keep getting "Object reference not set to an instance of an object." If I change the string value I am trying to get information from to Shell within the same key it works fine. Can anyone explain why one works and the other doesn't? I have verified that DefaultPassword is in my registry and I have given it a value or password.
Thanks,
Dustin
private void Form1_Load(object sender, EventArgs e)
{
try
{
loadReg();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
void loadReg()
{
Key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon", true);
string Val;
//Doesn't work
Val = Key.GetValue("DefaultPassword").ToString();
//Works
//Val = Key.GetValue("Shell").ToString();
textBox1.Text = Val;
}
Thanks,
Dustin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I am developing on 64bit Windows 7. I also set the configuration manager to the x86 platform. I tried using your suggestion but got the same error. Eventually this app will run on a Windows XP machine if I can ever get it to read the key.
ASKER
Looks like I tested without verifing the key was present. it does work with what you gave me. How will this port to XP though? The code doesnt currently work on an XP 32bit machine.
ASKER
I got it, thanks for the help!
Glad to help :)
Open in new window