checking whether key value exist or not using C#
c#, visual-studio
Solution
With a registry key, you can try to get it with the `OpenSubKey` method. If the returned value is `null`, then the key does not exist. I'm talking about keys here, not values.
In your example, that would come down to:
var key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\{4CHJHSDJHSJHDJS-SDGSJAD}");
if (key == null)
{
// Key does not exist
}
else
{
// Key exists
}
Problem
I have a key as "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\{4CHJHSDJHSJHDJS-SDGSJAD}" in my registry. using ``` Registry.GetValue("keyname", "valuename", "default value") ``` i can retrieve any value of it. But I need to check whether "{4CHJHSDJHSJHDJS-SDGSJAD}" exists in the registry or not. Can anybody suggest me what check I should use to do this?