Reputation: 1731
Is there a reliable, programmatic way to determine that Microsoft Edge is the default browser?
I know one option would be to use the IApplicationAssociationRegistration::QueryCurrentDefault method to return the default application registered for http. It's unclear that the ProgID returned by this call is a fixed string though so it may not be the best way to verify that Edge is indeed the default browser.
Upvotes: 4
Views: 4467
Reputation: 5817
Use the following code snippet. Haven't tested with Firefox or any of the other strange ones, but you'll get the following return values based on your default browser in Windows 10.
Code snippet below should work. Tested in a console app. If anyone wants a VB version let me know.
using Microsoft.Win32;
public static class BrowserUtils
{
static public string GetSystemDefaultBrowser()
{
string _retval = string.Empty;
const string userChoice = @"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice";
using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(userChoice))
{
if (userChoiceKey == null)
{
_retval = "unknown-> userChoiceKey returned null";
}
object progIdValue = userChoiceKey.GetValue("Progid");
if (progIdValue == null)
{
_retval = "unknown->GetValue(Progid) returned null";
}
//_retval = String.Format("progId=[{0}]", progIdValue.ToString());
_retval = progIdValue.ToString();
}
return _retval;
}
}
Hope this helps. Healy in Tampa.
Upvotes: 6