From bfce323e41f3f24062de213e88f32f5f7d5d0fbd Mon Sep 17 00:00:00 2001 From: rcourtman Date: Fri, 28 Nov 2025 09:58:47 +0000 Subject: [PATCH] Fix silent sc.exe delete failures in install.ps1 - Add error handling for sc.exe delete in uninstall logic - Add error handling for legacy agent service deletion - Add error handling for existing service deletion before reinstall - Show warnings when service deletion fails instead of silently continuing Related to #735 --- scripts/install.ps1 | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 97a6ac95a..e5b99cf34 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -120,7 +120,14 @@ if ($Uninstall) { if (Get-Service $AgentName -ErrorAction SilentlyContinue) { Stop-Service $AgentName -Force -ErrorAction SilentlyContinue - sc.exe delete $AgentName | Out-Null + $scOutput = sc.exe delete $AgentName 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Warning: Failed to delete service: $scOutput" -ForegroundColor Yellow + } else { + Write-Host "Service deleted successfully" -ForegroundColor Green + } + } else { + Write-Host "Service '$AgentName' not found (already removed)" -ForegroundColor Yellow } Remove-Item "$InstallDir\$BinaryName" -Force -ErrorAction SilentlyContinue @@ -236,7 +243,10 @@ Write-Host "Checking for legacy agents..." -ForegroundColor Cyan if (Get-Service "PulseHostAgent" -ErrorAction SilentlyContinue) { Write-Host "Removing legacy PulseHostAgent..." -ForegroundColor Yellow Stop-Service "PulseHostAgent" -Force -ErrorAction SilentlyContinue - sc.exe delete "PulseHostAgent" | Out-Null + $scOutput = sc.exe delete "PulseHostAgent" 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Warning: Failed to delete PulseHostAgent service: $scOutput" -ForegroundColor Yellow + } Remove-Item "C:\Program Files\Pulse\pulse-host-agent.exe" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } @@ -244,7 +254,10 @@ if (Get-Service "PulseHostAgent" -ErrorAction SilentlyContinue) { if (Get-Service "PulseDockerAgent" -ErrorAction SilentlyContinue) { Write-Host "Removing legacy PulseDockerAgent..." -ForegroundColor Yellow Stop-Service "PulseDockerAgent" -Force -ErrorAction SilentlyContinue - sc.exe delete "PulseDockerAgent" | Out-Null + $scOutput = sc.exe delete "PulseDockerAgent" 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Warning: Failed to delete PulseDockerAgent service: $scOutput" -ForegroundColor Yellow + } Remove-Item "C:\Program Files\Pulse\pulse-docker-agent.exe" -Force -ErrorAction SilentlyContinue Start-Sleep -Seconds 2 } @@ -254,8 +267,12 @@ Write-Host "Installing binary..." -ForegroundColor Cyan # Stop existing service if running if (Get-Service $AgentName -ErrorAction SilentlyContinue) { + Write-Host "Removing existing $AgentName service..." -ForegroundColor Yellow Stop-Service $AgentName -Force -ErrorAction SilentlyContinue - sc.exe delete $AgentName | Out-Null + $scOutput = sc.exe delete $AgentName 2>&1 + if ($LASTEXITCODE -ne 0) { + Write-Host "Warning: Failed to delete existing service: $scOutput" -ForegroundColor Yellow + } Start-Sleep -Seconds 2 }