Repository navigation
Fix winapp run --unregister-on-exit leaving the package registered when not elevated - #1067
Conversation
GetPackageFullName used PackageManager.FindPackages(family), which searches all users and requires admin rights. Non-elevated, it threw, the error was swallowed into null, and the package was left registered. Use the current-user FindPackagesForUser(string.Empty, family) instead. Fixes #1065 Co-authored-by: Copilot App <[email protected]> Copilot-Session: b544b999-3f5c-4c9c-8f23-c10d35dd2d2b
Elevated, the all-users lookup also succeeds, so the test could not detect the regression; report Inconclusive instead of a misleading pass. Co-authored-by: Copilot App <[email protected]> Copilot-Session: b544b999-3f5c-4c9c-8f23-c10d35dd2d2b
There was a problem hiding this comment.
🟢 Approval recommended
The fix matches the existing lookup pattern, builds in Release, and all 30 targeted tests passed or skipped as expected.
0 open findings
What changed in this PR
Updates package lookup to work without elevation, fixing cleanup after winapp run --unregister-on-exit.
Changes:
- Scopes package lookup to the current user.
- Adds a non-elevated regression test.
| File | Description |
|---|---|
AppLauncherService.cs |
Uses the current-user package query. |
AppLauncherServiceTests.cs |
Verifies lookup without administrator rights. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…ter-on-exit-elevation
Build Metrics ReportValidation passed. All required build and validation jobs succeeded. Binary Sizes
.NET Test Results (TRX reports)Other suites are reflected in the overall validation status above. ✅ 8664 passed, 39 skipped out of 8703 tests in 1583.8s (+1 test, -5.8s vs. baseline) Test Coverage✅ 87.5% line coverage, 81.9% branch coverage · ✅ no change vs. baseline CLI Startup Time71ms median (x64, Try This BuildInstalls the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing. & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 1067Switching between builds often?Put the tool on your PATH once: & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPathThen this build is just: winapp-pr 1067Run Updated 2026-10-13 23:45:42 UTC · commit |
Description
winapp run --unregister-on-exitnever removed the package when run from a normal (non-admin) terminal. To unregister, winapp looks up the package's full name, and that lookup used a Windows API that searches all users' packages and requires admin rights. Without elevation it failed, the failure was treated as "not found", and winapp left the package registered with a warning.The lookup now searches only the current user's packages, which needs no elevation. This is the same query the neighboring registration check in
AppLauncherServicealready uses. It applies to everyrunmode that supports--unregister-on-exit(folder, project, and single-file).Usage Example
Observed in a non-elevated terminal with a minimal packaged
app.csfile-based app:Before (released 0.7.1):
After (this branch, Release Native AOT publish):
Related Issue
Fixes #1065
Type of Change
Checklist
Screenshots / Demo
N/A (CLI output above).
Additional Notes
Validation (Windows 11 arm64, non-elevated):
dotnet run --project src/winapp-CLI/WinApp.Cli.Tests/WinApp.Cli.Tests.csproj -- --filter "FullyQualifiedName~AppLauncherServiceTests": 30/30 passed. The new test failed on the unfixed code.dotnet publish -c Release -r win-arm64followed by the before/after run above.The new test only proves the fix when tests run without admin rights. As admin, the old all-users lookup also succeeds, so the test reports Inconclusive (counted as skipped) instead of passing without checking the fix.
Not exercised:
--on sandboxguest launch, which uses the same lookup only to launch the app (it never unregisters).