From a6d59c0dc15391dba743cc4706c9c3ae635859ba Mon Sep 17 00:00:00 2001 From: HetCreep Date: Mon, 22 Jun 2026 19:53:45 +0700 Subject: [PATCH] fix(app-removal): detect WinGet uninstall failures by exit code, not English text (#658) --- Scripts/AppRemoval/RemoveApps.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Scripts/AppRemoval/RemoveApps.ps1 b/Scripts/AppRemoval/RemoveApps.ps1 index 8d31296..9228a3e 100644 --- a/Scripts/AppRemoval/RemoveApps.ps1 +++ b/Scripts/AppRemoval/RemoveApps.ps1 @@ -82,12 +82,17 @@ function RemoveApps { } else { # Uninstall app via WinGet - $wingetOutput = Invoke-NonBlocking -ScriptBlock { + $wingetResult = Invoke-NonBlocking -ScriptBlock { param($appId) - winget uninstall --accept-source-agreements --disable-interactivity --id $appId + $global:LASTEXITCODE = 0 + $output = winget uninstall --accept-source-agreements --disable-interactivity --id $appId + [PSCustomObject]@{ ExitCode = $LASTEXITCODE; Output = $output } } -ArgumentList $app - $wingetFailed = Select-String -InputObject $wingetOutput -Pattern "Uninstall failed with exit code|No installed package found matching input criteria|No package found matching input criteria" -SimpleMatch:$false + # winget reports success/failure via its exit code, which is locale-independent. + # The previous match on English console text silently passed on non-English Windows. + # Treat a null result (timed out / not run) or any non-zero exit code as a failure. + $wingetFailed = ($null -eq $wingetResult) -or ($wingetResult.ExitCode -ne 0) if ($isEdgeId) { if (-not $wingetFailed) { $edgeUninstallSucceeded = $true @@ -117,6 +122,9 @@ function RemoveApps { } } } + elseif ($wingetFailed) { + Write-Host "Unable to uninstall $app via WinGet" -ForegroundColor Red + } } continue