I have c# application which include code to retrieve registry values and check it’s values.registry values stored in following manner:
MainKey:
Name:user123
Isregistered:no
however if Isregistered returns “no”,it will display appropriate message.
i am getting error like this
Object reference not set to an instance of an object.
C# Code:
RegistryKey reg = Registry.LocalMachine.OpenSubKey(@"HKEY_CURRENT_USER\\MainKey", true);
string currentKey;
currentKey = reg.GetValue("Isregistered", true).ToString();
if (currentKey == "yes")
{
Console.WriteLine("availble");
}
else
{
Console.WriteLine("Not availble");
}
i am getting error on
“currentKey = reg.GetValue(“Isregistered”, true).ToString();”
I see two problems in your code:
1)
Find more about CurrentUser field here
2)
The other aspect is that either use @ or \\ not both in the registry path. i.e.
or
Find more about verbatim string literals here