Files
screenjob/uninstall_backend_service.ps1
2026-05-31 20:43:36 +02:00

46 lines
1.4 KiB
PowerShell

[CmdletBinding(SupportsShouldProcess = $true)]
param(
[switch]$AllUsers,
[string]$ServiceName = "ScreenJobBackend"
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$scriptDir = Split-Path -Parent $PSCommandPath
$shortcutName = "ScreenJob Backend.lnk"
$startupFolder = if ($AllUsers) {
[Environment]::GetFolderPath("CommonStartup")
} else {
[Environment]::GetFolderPath("Startup")
}
$shortcutPath = Join-Path $startupFolder $shortcutName
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if ($null -ne $service) {
if ($PSCmdlet.ShouldProcess($ServiceName, "Remove legacy Windows service")) {
if ($service.Status -ne "Stopped") {
Stop-Service -Name $ServiceName -Force -ErrorAction Stop
}
& sc.exe delete $ServiceName | Out-Null
if ($LASTEXITCODE -ne 0) {
throw "Failed to delete service '$ServiceName' (sc.exe exit code $LASTEXITCODE)."
}
Write-Host "Removed legacy Windows service: $ServiceName"
}
}
if (Test-Path -LiteralPath $shortcutPath) {
if ($PSCmdlet.ShouldProcess($shortcutPath, "Remove backend startup shortcut")) {
Remove-Item -LiteralPath $shortcutPath -Force
Write-Host "Removed backend startup shortcut: $shortcutPath"
}
} else {
Write-Host "No backend startup shortcut found at: $shortcutPath"
}
Write-Host "Backend launcher uninstalled successfully." -ForegroundColor Green