Fix default browser detection for Windows 11 24H2 by checking UserChoiceLatest registry key (#40035)
Some checks failed
Spell checking / Check Spelling (push) Has been cancelled
Spell checking / Report (Push) (push) Has been cancelled
Spell checking / Report (PR) (push) Has been cancelled
Spell checking / Update PR (push) Has been cancelled

## Summary

This PR fixes an issue where PowerToys Web Search and PowerToys Run
would always open Microsoft Edge instead of the user's default browser
on Windows 11 24H2, even when a different browser like Firefox was set
as the default.

## Root Cause

Windows 11 24H2 introduced a change where default browser associations
are now stored in a new registry location:
- **New location**:
`HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoiceLatest`
- **Old location**:
`HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice`

PowerToys was only checking the old registry location, causing it to
fail to find the default browser and fall back to Microsoft Edge.

## Changes Made

Updated both `DefaultBrowserInfo.cs` files to check the new registry
location first, then fall back to the old location for backward
compatibility:

1. **Command Palette Web Search**:
`src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WebSearch/Helpers/DefaultBrowserInfo.cs`
2. **PowerToys Run**:
`src/modules/launcher/Wox.Plugin/Common/DefaultBrowserInfo.cs`

**Before**:
```csharp
var progId = GetRegistryValue(
    @"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
    "ProgId");
```

**After**:
```csharp
var progId = GetRegistryValue(
    @"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoiceLatest",
    "ProgId")
    ?? GetRegistryValue(
        @"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
        "ProgId");
```

## Testing

- Verified the fallback logic works correctly with a test application
- Confirmed both affected files are updated with the same pattern
- Ensured backward compatibility with older Windows versions

## Impact

This fix ensures that:
- Users on Windows 11 24H2 will have their default browser respected
- Older Windows versions continue to work as before
- No breaking changes are introduced

Fixes #39794.

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: crutkas <1462282+crutkas@users.noreply.github.com>
This commit is contained in:
Copilot 2025-06-18 09:16:23 -07:00 committed by GitHub
parent 4737ec987e
commit 09c9eeb48e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -79,8 +79,11 @@ public static class DefaultBrowserInfo
try
{
var progId = GetRegistryValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
"ProgId");
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoiceLatest",
"ProgId")
?? GetRegistryValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
"ProgId");
var appName = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\Application", "ApplicationName")
?? GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}", "FriendlyTypeName");

View File

@ -80,8 +80,11 @@ namespace Wox.Plugin.Common
try
{
string progId = GetRegistryValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
"ProgId");
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoiceLatest",
"ProgId")
?? GetRegistryValue(
@"HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice",
"ProgId");
string appName = GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}\Application", "ApplicationName")
?? GetRegistryValue($@"HKEY_CLASSES_ROOT\{progId}", "FriendlyTypeName");