fix: prioritize modified QuietUninstallString and append /uninstall to bare executables

This commit is contained in:
2025-12-22 17:17:40 +01:00
parent 9561bc85a5
commit 3fac7d256c

View File

@@ -319,21 +319,34 @@ function Invoke-UninstallSoftware {
continue continue
} }
# Use Quiet String if available? No, user requested "Non Quietly" to debug. # STRATEGY: Prefer QuietUninstallString if available.
# But if standard fails, we see it now. # We strip the "quiet" flags to make it interactive.
$finalCmd = "$rawCmd" if (-not [string]::IsNullOrWhiteSpace($quietCmd)) {
Write-Host " [i] Quiet Uninstall String found. Adapting for interactive mode..." -ForegroundColor Cyan
$finalCmd = $quietCmd -replace "(?i)\s*/qn", "" `
-replace "(?i)\s*/quiet", "" `
-replace "(?i)\s*/norestart", "" `
-replace "(?i)\s*/silent", "" `
-replace "(?i)\s*/s\b", ""
} else {
$finalCmd = $rawCmd
}
# FIX: Some MSI commands use /I (Install/Configure) instead of /X (Uninstall). # FIX: Some MSI commands use /I (Install/Configure) instead of /X (Uninstall).
# We force /X to ensure it triggers the removal process. if ($finalCmd -match "(?i)msiexec.*\/I\s*\{") {
if ($finalCmd -match "(?i)msiexec.*\/I\s*{") {
Write-Host " [!] Detected MSI Install flag (/I). Swapping to Uninstall flag (/X)..." -ForegroundColor Magenta Write-Host " [!] Detected MSI Install flag (/I). Swapping to Uninstall flag (/X)..." -ForegroundColor Magenta
$finalCmd = $finalCmd -replace "(?i)\/I", "/X" $finalCmd = $finalCmd -replace "(?i)\/I", "/X"
} }
# FIX: If command is just "setup.exe" with no arguments, it often reinstalls.
if ($finalCmd -match '^"?.*\.exe"?$') {
Write-Host " [!] Detected bare executable. Appending /uninstall..." -ForegroundColor Magenta
$finalCmd = "$finalCmd /uninstall"
}
Write-Host " Executing: $($finalCmd)" -ForegroundColor Cyan Write-Host " Executing: $($finalCmd)" -ForegroundColor Cyan
try { try {
# Use WindowStyle Normal so the user can see the uninstaller
Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "$finalCmd" -Wait -WindowStyle Normal Start-Process -FilePath "cmd.exe" -ArgumentList "/c", "$finalCmd" -Wait -WindowStyle Normal
} catch { } catch {
Write-Host " [!] Error launching: $($_.Exception.Message)" -ForegroundColor Red Write-Host " [!] Error launching: $($_.Exception.Message)" -ForegroundColor Red