I can’t seem to get my program to correctly read the registry. Below is my current code, but I’ve tried others stuff as well. It compiles and runs, but it always returns a zero. (I’ve double checked in the registry, and the value is set at one. “0x000000001(1)” The key I am trying to access is a DWord, and the value should only be a 1 or 0. I am running as admin, so I have full access privileges. What am I doing wrong?
Registry.LocalMachine.OpenSubKey( "SOFTWARE", true );
RegistryKey masterKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Authentication\\LogonUI\\Background");
string value = "";
if( masterKey != null )
{
value = masterKey.GetValue( "OEMbackground", 2 ).ToString();
}
masterKey.Close();
myLabel.Text=value;
I suspect you’re running on a 64-bit machine but as a 32-bit process. That value probably doesn’t exist in your 32-bit registry but in the 64-bit registry (that’s certainly the case on mine). You’ll probably need to access the 64-bit hive to be able to read that value. It shouldn’t be a problem from a 32-bit process.