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?
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
}
Have you tried this
using Microsoft.Win32;
RegistryKey myregistry = Registry.CurrentUser.OpenSubKey("MyKey");
if (myregistry != null)
{
string Value=myregistry.GetValue("ID").ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With