diff --git a/installer/setup.ps1 b/installer/setup.ps1
index 61440b3..caf7fc4 100644
--- a/installer/setup.ps1
+++ b/installer/setup.ps1
@@ -2,7 +2,8 @@ param(
[string]$ServerId,
[string]$Token,
[string]$ServerUrl,
- [string]$InstallDir
+ [string]$InstallDir,
+ [switch]$Uninstall
)
$ErrorActionPreference = "Stop"
@@ -17,15 +18,48 @@ function Write-Log($msg) {
# Fail native-exe (nssm) calls loudly: check $LASTEXITCODE after each call
function Invoke-Native {
- param([string]$File, [string[]]$Args)
- Write-Log ("RUN: {0} {1}" -f $File, ($Args -join " "))
- $out = & $File @Args 2>&1
+ param([string]$File, [string[]]$Arguments)
+ Write-Log ("RUN: {0} {1}" -f $File, ($Arguments -join " "))
+ $out = & $File @Arguments 2>&1
if ($out) { Write-Log ("OUT: {0}" -f ($out -join "`n")) }
if ($LASTEXITCODE -ne 0) {
throw ("{0} exited {1}" -f $File, $LASTEXITCODE)
}
}
+# Like Invoke-Native but never throws — for teardown, where a missing/stopped
+# service must not abort the uninstall.
+function Invoke-NativeSoft {
+ param([string]$File, [string[]]$Arguments)
+ Write-Log ("RUN(soft): {0} {1}" -f $File, ($Arguments -join " "))
+ $out = & $File @Arguments 2>&1
+ if ($out) { Write-Log ("OUT: {0}" -f ($out -join "`n")) }
+ Write-Log ("EXIT: {0}" -f $LASTEXITCODE)
+}
+
+if ($Uninstall) {
+ try {
+ Write-Log "=== teardown start ==="
+ if (-not $InstallDir) { $InstallDir = $PSScriptRoot }
+ $nssm = Join-Path $InstallDir "nssm.exe"
+ if (Test-Path $nssm) {
+ Invoke-NativeSoft -File $nssm -Arguments @("stop", "VantageAgent")
+ Invoke-NativeSoft -File $nssm -Arguments @("remove", "VantageAgent", "confirm")
+ } else {
+ Write-Log "nssm.exe not found at $nssm - using sc.exe fallback"
+ Invoke-NativeSoft -File "sc.exe" -Arguments @("stop", "VantageAgent")
+ Invoke-NativeSoft -File "sc.exe" -Arguments @("delete", "VantageAgent")
+ }
+ Write-Log "=== teardown ok ==="
+ exit 0
+ }
+ catch {
+ Write-Log ("TEARDOWN ERROR: {0}" -f $_.Exception.Message)
+ # Never block uninstall
+ exit 0
+ }
+}
+
try {
Write-Log "=== setup start ==="
Write-Log ("ServerId={0} ServerUrl={1} InstallDir={2}" -f $ServerId, $ServerUrl, $InstallDir)
@@ -46,7 +80,7 @@ tls: true
Write-Log "wrote $cfgPath"
# Lock down ACL: SYSTEM + Administrators only
- Invoke-Native -File "icacls" -Args @($cfgPath, "/inheritance:r", "/grant:r", "SYSTEM:F", "Administrators:F")
+ Invoke-Native -File "icacls" -Arguments @($cfgPath, "/inheritance:r", "/grant:r", "SYSTEM:F", "Administrators:F")
if (-not $InstallDir) { $InstallDir = $PSScriptRoot }
$nssm = Join-Path $InstallDir "nssm.exe"
@@ -55,9 +89,9 @@ tls: true
if (-not (Test-Path $nssm)) { throw "nssm.exe not found at $nssm" }
if (-not (Test-Path $exe)) { throw "vantage-agent.exe not found at $exe" }
- Invoke-Native -File $nssm -Args @("install", "VantageAgent", $exe)
- Invoke-Native -File $nssm -Args @("set", "VantageAgent", "Start", "SERVICE_AUTO_START")
- Invoke-Native -File $nssm -Args @("start", "VantageAgent")
+ Invoke-Native -File $nssm -Arguments @("install", "VantageAgent", $exe)
+ Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "Start", "SERVICE_AUTO_START")
+ Invoke-Native -File $nssm -Arguments @("start", "VantageAgent")
Write-Log "=== setup ok ==="
exit 0
diff --git a/installer/vantage-agent.wxs b/installer/vantage-agent.wxs
index 715dfcd..e4a53a9 100644
--- a/installer/vantage-agent.wxs
+++ b/installer/vantage-agent.wxs
@@ -59,8 +59,20 @@
+
+
+
+
+
+