Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PowerToys 右键菜单重复条目

问题

Windows 11 经典右键菜单中,File Locksmith 出现两个条目:一个中文,一个英文。

根因

PowerToys 0.99.1 的 File Locksmith 被两套机制同时注册,各自的显示名来源不同:

注册方式CLSID注册位置显示名来源
经典 ShellEx{84D68575-E186-46AD-B0CB-BAEB45EE29C0}AllFileSystemObjects\ShellEx\ContextMenuHandlers\FileLocksmithExtDLL 内 GetCommandString,随系统语言返回中文
AppX 现代版{AAF1E27D-4976-49C2-8895-AAFA743C0A7E}AppX 包的 desktop4:FileExplorerContextMenusPackage PRI 资源文件,仅含 en-us,显示英文

两条路径都注册在 AllFileSystemObjects 下,所以右键任何文件/文件夹都会同时触发两份,产生中英文两个条目。

排查过程

1. 拉出所有 PowerToys 相关注册表项

Get-ChildItem -Path "HKCR:\","HKCU:\Software\Classes" -Recurse -ErrorAction SilentlyContinue |
    Where-Object { $_.Name -match 'Locksmith' } |
    Select-Object -ExpandProperty Name

发现两条关键的 ContextMenuHandler 注册:

  • HKEY_CURRENT_USER\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers\FileLocksmithExt
  • HKEY_CURRENT_USER\Software\Classes\Drive\ShellEx\ContextMenuHandlers\FileLocksmithExt

2. 追踪 CLSID

Get-ItemProperty "HKCU:\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers\FileLocksmithExt"
# → {84D68575-E186-46AD-B0CB-BAEB45EE29C0}

查 CLSID 详情:

Get-ChildItem "HKCU:\Software\Classes\CLSID\{84D68575-E186-46AD-B0CB-BAEB45EE29C0}" -Recurse
# → InprocServer32: C:\Program Files\PowerToys\WinUI3Apps\PowerToys.FileLocksmithExt.dll
# → 这是经典 COM Shell Extension

3. 发现 AppX 并行注册

Get-AppxPackage -Name "*FileLocksmith*"
# → Microsoft.PowerToys.FileLocksmithContextMenu (AppX 包)

读 AppX Manifest:

<desktop4:Extension Category="windows.fileExplorerContextMenus">
  <desktop5:Verb Id="FileLocksmithCommand" Clsid="AAF1E27D-4976-49C2-8895-AAFA743C0A7E" />
</desktop4:Extension>

→ 这是文件管理器上下文菜单的现代注册方式,CLSID 与经典注册不同。

4. 结论

两套完全独立的注册并存 → 两个右键条目。

修复

保留 AppX 现代注册,删除经典 ShellEx 注册:

# 删除经典注册
Remove-Item "HKCU:\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers\FileLocksmithExt" -Force
Remove-Item "HKCU:\Software\Classes\Drive\ShellEx\ContextMenuHandlers\FileLocksmithExt" -Force

# 重启资源管理器
taskkill /f /im explorer.exe; start explorer.exe

验证

Test-Path "HKCU:\Software\Classes\AllFileSystemObjects\ShellEx\ContextMenuHandlers\FileLocksmithExt"
# → False ✓
Test-Path "HKCU:\Software\Classes\Drive\ShellEx\ContextMenuHandlers\FileLocksmithExt"
# → False ✓

注意事项

  • PowerToys 后续版本更新可能重新写入经典注册,届时间隔跑一次同样命令即可
  • 如果希望保留经典版而非 AppX 版,反向操作:删除 AppX 包 Get-AppxPackage -Name "*FileLocksmith*" | Remove-AppxPackage
  • shellshellex 是两套不同的注册机制,排查时两者都要查

GitHub 官方仓库追踪

此问题是 PowerToys 已知 bug,从 2022 年延续至今,影响 File Locksmith、PowerRename、Image Resizer 三个模块。

关键 Issue

Issue状态日期说明
#20255Open2022-09总跟踪 Issue,三个模块的重复都归到这里
#31701Open2024-03维护者确认:“Win11 tier1 menu is a msix package…ends up duping with classic context menu”
#32097Closed2024-03与本文完全一致:非英文系统,标准+扩展菜单,一英文一本地语言
#39699Open2025-05西班牙语系统,v0.91.1
#44394Open2025-12意大利语系统,v0.97.0,最新报告
#34080Closed (dup)2024-07中文用户报告 “powerrename、filelocksmith两项重复”

关键 PR:问题如何演变

PR日期作者影响
#313882024-02@stefansjfw引入 AppX 包 — File Locksmith 首次有了 Win11 tier1 现代菜单,但没有移除经典 ShellEx 注册,埋下隐患
#413512025-08@lei9444加剧问题 — 移除了 if (!IsWin11OrGreater()) 条件守卫,让 Win11 上经典 ShellEx 无条件注册。PR 描述承认了副作用:“Ensure Windows 11 adds the registry entries for the old context menu so that ‘Show more options’/classic menu always includes them”
#414112025-08@lei9444修了 GPO 禁用时注册表残留的问题,但未修重复

PR #41351 的核心代码变更

// 之前:Win11 只注册 AppX,不注册经典 ShellEx
if (!package::IsWin11OrGreater()) {
    FileLocksmithRuntimeRegistration::EnsureRegistered();  // 经典 COM 方式
}

// 之后:Win11 上经典 ShellEx 无条件注册 → 与 AppX 包重复
FileLocksmithRuntimeRegistration::EnsureRegistered();  // 经典 COM 方式

官方态度

  • 为了确保经典右键菜单(“显示更多选项”)中一定出现 File Locksmith,宁可接受重复也不愿冒菜单丢失的风险
  • 维护者在 #31701 的回复:“At the time we couldn’t find a solution that also supported keeping the context menus on for the cases where the win11 tier 1 menus don’t install or show properly”

社区其他 Workaround

除本文方案外,社区还提供了反向操作(删 AppX PackagedCom 注册,保留经典 ShellEx):

# 管理员 PowerShell
Get-ChildItem "Registry::HKEY_CLASSES_ROOT\PackagedCom\Package\Microsoft.PowerToys.FileLocksmithContextMenu_*\Class\*" |
    Remove-Item -Recurse

taskkill /f /im explorer.exe; start explorer.exe

两种方案原理相同:删掉两套注册中的一套,没有对错之分。