mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-07-02 22:58:34 +00:00
fix(app-removal): detect WinGet uninstall failures by exit code, not English text (#658)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user