From b6f0d74c55fde19e7fba1b4df0a2f82c1e8da36e Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sat, 29 Nov 2025 12:32:56 +0000 Subject: [PATCH] Use New-Service for Windows service creation Switch from sc.exe create to PowerShell's New-Service cmdlet for creating the Windows service. New-Service provides better error handling and is more reliable. Keep sc.exe only for configuring service recovery options (restart on failure), which New-Service doesn't support. Related to #776 --- scripts/install.ps1 | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 8cbbff304..cd2ba4204 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -314,18 +314,18 @@ if (-not [string]::IsNullOrWhiteSpace($AgentId)) { $ServiceArgs += @("--agent-id $BinPath = "`"$DestPath`" $($ServiceArgs -join ' ')" -# Create Service with error handling -$scOutput = sc.exe create $AgentName binPath= "$BinPath" start= auto displayname= "Pulse Unified Agent" 2>&1 -if ($LASTEXITCODE -ne 0) { - Show-Error "Failed to create service '$AgentName'.`nsc.exe output: $scOutput" +# Create Service using New-Service (more reliable than sc.exe create) +try { + New-Service -Name $AgentName ` + -BinaryPathName $BinPath ` + -DisplayName "Pulse Unified Agent" ` + -Description "Pulse Unified Agent for Host and Docker monitoring" ` + -StartupType Automatic | Out-Null + Write-Host "Service created successfully" -ForegroundColor Green +} catch { + Show-Error "Failed to create service '$AgentName'.`nError: $_" Exit 1 } -Write-Host "Service created successfully" -ForegroundColor Green - -$scOutput = sc.exe description $AgentName "Pulse Unified Agent for Host and Docker monitoring" 2>&1 -if ($LASTEXITCODE -ne 0) { - Write-Host "Warning: Failed to set service description: $scOutput" -ForegroundColor Yellow -} $scOutput = sc.exe failure $AgentName reset= 86400 actions= restart/5000/restart/5000/restart/5000 2>&1 if ($LASTEXITCODE -ne 0) {