I saw several posts on how to read registry key value on here and I think I am doing it all right but the key I read in my case is always null for some reason.
In HKLM\SOFTWARE
, I created key MyCompany
and then within that key, I created another key MyApp
like:
HKLM\SOFTWARE\MyCompany\MyApp
In this key, I added a string string value "MySetting"
I am trying to read that value using following code:
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MyCompany\MyApp", false))
{
string spaUrl = (String)key.GetValue("MySetting");
}
but the key is always null even though I have these keys and value set at the location above. Any idea what I am doing wrong?
I get
System.NullReferenceException was unhandled exception because key is always null.
SOLUTION
Thanks to Luke Merrett answer below, I modify the location of my keys to be in HKLM\SOFTWARE\WOW6432Node
and that worked. Thanks Luke