33 lines
929 B
PowerShell
33 lines
929 B
PowerShell
|
|
<#
|
||
|
|
.SYNOPSIS
|
||
|
|
Stop and remove the FlatRender Node Agent Windows service.
|
||
|
|
.EXAMPLE
|
||
|
|
.\uninstall-service.ps1
|
||
|
|
#>
|
||
|
|
param(
|
||
|
|
[string]$ServiceName = "FlatRenderNodeAgent"
|
||
|
|
)
|
||
|
|
|
||
|
|
$ErrorActionPreference = "Stop"
|
||
|
|
|
||
|
|
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
||
|
|
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
||
|
|
Write-Error "This script must be run as Administrator."
|
||
|
|
exit 1
|
||
|
|
}
|
||
|
|
|
||
|
|
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||
|
|
if (-not $svc) {
|
||
|
|
Write-Host "Service '$ServiceName' is not installed — nothing to do."
|
||
|
|
exit 0
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($svc.Status -ne 'Stopped') {
|
||
|
|
Write-Host "Stopping '$ServiceName'..."
|
||
|
|
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
|
||
|
|
Start-Sleep -Seconds 2
|
||
|
|
}
|
||
|
|
|
||
|
|
& sc.exe delete $ServiceName | Out-Null
|
||
|
|
Write-Host "✓ Service '$ServiceName' removed." -ForegroundColor Green
|