Skip to content

Fix winapp run --unregister-on-exit leaving the package registered when not elevated - #1067

Merged
Nikola Metulev (nmetulev) merged 4 commits into
mainfrom
zateutsch-fix-unregister-on-exit-elevation
Oct 14, 2026
Merged

Nikola Metulev (nmetulev) merged 4 commits into
mainfrom
zateutsch-fix-unregister-on-exit-elevation

Conversation

@zateutsch

Copy link
Copy Markdown
Contributor

Description

winapp run --unregister-on-exit never 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 AppLauncherService already uses. It applies to every run mode that supports --unregister-on-exit (folder, project, and single-file).

Usage Example

Observed in a non-elevated terminal with a minimal packaged app.cs file-based app:

Before (released 0.7.1):

> winapp run app.cs --unregister-on-exit
hello from packaged app
⚠ Could not determine which package 'winapp.review.issue1065' registered, so it was left registered. Remove it with 'winapp unregister'.
> Get-AppxPackage winapp.review.issue1065
winapp.review.issue1065_1.0.0.0_arm64__wa48hzj8jr8y6   # still registered

After (this branch, Release Native AOT publish):

> winapp run app.cs --unregister-on-exit
hello from packaged app
> Get-AppxPackage winapp.review.issue1065
                                                        # nothing: removed

Related Issue

Fixes #1065

Type of Change

  • 🐛 Bug fix

Checklist

  • New tests added for new functionality (if applicable)
  • Tested locally on Windows

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-arm64 followed 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 sandbox guest launch, which uses the same lookup only to launch the app (it never unregisters).

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
Copilot AI balanced review requested due to automatic review settings October 12, 2026 23:08
@zateutsch Zach Teutsch (zateutsch) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Oct 12, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 59.42 MB 59.42 MB 📉 -0.5 KB (-0.00%)
CLI (x64) 59.41 MB 59.41 MB 📉 -0.5 KB (-0.00%)
MSIX (ARM64) 24.66 MB 24.66 MB 📉 -0.7 KB (-0.00%)
MSIX (x64) 26.19 MB 26.19 MB 📈 +0.1 KB (+0.00%)
NPM Package 51.47 MB 51.46 MB 📉 -2.2 KB (-0.00%)
NuGet Package 51.58 MB 51.58 MB 📉 -1.3 KB (-0.00%)

.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 Time

71ms median (x64, winapp --version) · ✅ no change vs. baseline

Try This Build

Installs 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))) 1067
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 1067

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-10-13 23:45:42 UTC · commit acdb1f5 · workflow run

@zateutsch Zach Teutsch (zateutsch) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge and removed agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 13, 2026
@nmetulev
Nikola Metulev (nmetulev) merged commit 0085339 into main Oct 14, 2026
40 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the zateutsch-fix-unregister-on-exit-elevation branch October 14, 2026 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: winapp run --unregister-on-exit leaves the package registered when not elevated

3 participants