Fix Keyboard Manager editor file picker not opening when elevated#48876
Open
niels9001 wants to merge 1 commit into
Open
Fix Keyboard Manager editor file picker not opening when elevated#48876niels9001 wants to merge 1 commit into
niels9001 wants to merge 1 commit into
Conversation
The new WinUI 3 Keyboard Manager editor used the legacy Windows.Storage.Pickers (FileOpenPicker/FolderPicker), which activate through the UWP runtime broker and fail with E_ACCESSDENIED when the process is elevated. Because the editor is launched from the (often elevated) runner, clicking the browse buttons for the Run Program action's program path / start-in folder did nothing. Switch to the Windows App SDK Microsoft.Windows.Storage.Pickers, which wrap the in-process Win32 Common Item Dialog (IFileOpenDialog, CLSCTX_INPROC_SERVER) and work correctly in elevated processes - the same approach already used elsewhere in PowerToys. Also wrap the handlers in try/catch with logging. Fixes #48845 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #48845.
In the new WinUI 3 Keyboard Manager editor, clicking the browse icon to select a program path (or "start in" folder) for the Run Program action did nothing — no dialog appeared.
Root cause
The editor (
PowerToys.KeyboardManagerEditorUI.exe) is launched by the Keyboard Manager module DLL viaShellExecuteExWfrom inside the PowerToys runner (src/modules/keyboardmanager/dll/dllmain.cpp). When PowerToys runs elevated, the editor inherits that elevation.The browse buttons used the legacy
Windows.Storage.Pickers(FileOpenPicker/FolderPicker+InitializeWithWindow). Those pickers activate through the UWP runtime broker, which fails withE_ACCESSDENIEDin an elevated process. The handlers wereasync voidwith notry/catch, so the exception was swallowed and no dialog ever opened. Typing/pasting a path into the field still worked — matching the bug report.Fix
Switch both handlers to the Windows App SDK
Microsoft.Windows.Storage.PickersAPI, constructed with aWindowId. Those pickers are a thin wrapper over the in-process Win32 Common Item Dialog (IFileOpenDialog,CLSCTX_INPROC_SERVER) and work correctly in elevated processes — the same mechanism already used elsewhere in PowerToys (e.g. Settings UIIFileDialog/GetOpenFileName, and CmdPal which already uses this exact namespace). Also wrapped the handlers intry/catchwithLogger.LogErrorso any future failure is logged instead of silently swallowed.Verification
KeyboardManagerEditorUI.csproj(Release / x64) with all native dependencies — exit code 0.Microsoft.Windows.Storage.Pickers.FileOpenPickerusescreate_instance<IFileOpenDialog>(CLSID_FileOpenDialog, CLSCTX_INPROC_SERVER)anddialog->Show(hwnd), i.e. the elevation-safe in-process dialog.Notes / out of scope
The report also mentions some apps (e.g.
visio.exe) not launching while others (winword.exe) do. That's a separate issue in the launch path (run_non_elevatedusesCreateProcessW, which ignores registry App Paths / shell activation, unlikeShellExecuteused by the Open URI action) and is not addressed here.