I followed several hints on how to get the "default browser" in windows, but they all are how to read the registry path from Current.User: Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
HOWEVER, I have both Chrome and Edge on my machine. When switching between the two as the default, I always get "ChromeHTML". So, this does not seem like it will work!
This happens to be for a .NET MAUI app
1 Answer 1
This works on Windows 11:
internal static bool TryGetSystemDefaultBrowserPath(out string path)
{
path = string.Empty;
try
{
using var regDefault = Registry.CurrentUser.OpenSubKey(
name: "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.htm\\UserChoice",
writable: false);
if (regDefault?.GetValue("ProgId") is not string { Length: > 0 } stringDefault)
{
return false;
}
using var regKey = Registry.ClassesRoot.OpenSubKey(
name: stringDefault + "\\shell\\open\\command",
writable: false);
if (regKey?.GetValue(null) is not string raw ||
string.IsNullOrWhiteSpace(raw))
{
return false;
}
var name = raw.Trim().Trim('"');
var exeIndex = name.IndexOf(".exe", StringComparison.OrdinalIgnoreCase);
if (exeIndex < 0)
{
return false;
}
name = name[..(exeIndex + 4)];
path = name;
return true;
}
catch
{
return false;
}
}
answered Sep 22, 2025 at 1:43
Andrew KeepCoding
15.5k2 gold badges26 silver badges41 bronze badges
Sign up to request clarification or add additional context in comments.
5 Comments
Andrew KeepCoding
@bobwki You've set the bounty after I posted this answer. Does that mean that this answer didn't solve your issue?
bobwki
well, on my system it always returned "ChromeHTML", whether set to Chrome or Edge. So, no. I appreciated your answer, though, so I upvoted.
Andrew KeepCoding
This method returns the "path" to the default browser. Can you check again?
bobwki
I tried again today, and, maddeningly, when I changed default browser to Edge, and restarted Windows, and verified by using the Windows Search box to open my website, your call still returns CHROME -- C:\Program Files\Google\Chrome\Application\chrome.exe. Hard to believe...
bobwki
EVEN MORE MADDENING -- I uninstalled Chrome. Now your code returns "false". "stringDefault" is set to "ChromeHTML", which leads to the next OpenSubKey to return NULL.
Explore related questions
See similar questions with these tags.
ProgIdvalue? What do you see underHKEY_CLASSES_ROOT\ChromeHTML?