Iterate through registry entries

Viewed 28847

As suggested here, I need to iterate through entries in

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\

to find out the installed path of my application. How to iterate so that I can find out the InstallLocation value given the DisplayName. How to do it efficiently in C#.

2 Answers
using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Whater\The\Key"))
{
  if (key != null)
  {
    foreach (string ValueOfName in key.GetValueNames())
    {
      try
      {
         bool Value = bool.Parse((string)key.GetValue(ValueOfName));
      }
      catch (Exception ex) {}
    }
 }
}

With a bool cast :D - so the string is expected to be True or False.

For the user registry hive use Registry.CurrentUser instead of Registry.LocalMachine

Related