public static IEnumerable<Browser> GetBrowsers()
{
RegistryKey browserKeys;
string[] keys;
try
{
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
if (browserKeys == null)
browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
if (browserKeys is null)
{
Log.DebugWrite(nameof(SeleniumAuthenticator), "Could not open registry");
yield break;
}
keys = browserKeys.GetSubKeyNames();
if (keys is null)
{
Log.DebugWrite(nameof(SeleniumAuthenticator), "No sub keys found");
yield break;
}
}
catch (Exception ex)
{
Log.DebugWrite(nameof(SeleniumAuthenticator), ex, "Failed to read regex");
yield break;
}
foreach (var key in keys)
{
Browser browser = new Browser();
try
{
RegistryKey browserKey = browserKeys.OpenSubKey(key);
if (browserKey is null) continue;
browser.Name = (string)browserKey.GetValue(null);
RegistryKey browserKeyPath = browserKey.OpenSubKey(@"shell\open\command");
browser.Path = StripQuotes(browserKeyPath.GetValue(null).ToString());
RegistryKey browserIconPath = browserKey.OpenSubKey(@"DefaultIcon");
browser.IconPath = StripQuotes(browserIconPath.GetValue(null).ToString());
if (browser.Path != null)
browser.Version = FileVersionInfo.GetVersionInfo(browser.Path).FileVersion;
else
browser.Version = "unknown";
}
catch (Exception ex)
{
Log.DebugWrite(nameof(SeleniumAuthenticator), ex, "Failed to read value from regex");
continue;
}
yield return browser;
}
}