Files

24 lines
724 B
PowerShell
Raw Permalink Normal View History

param(
[string]$ServiceName = "QYZH.InteractiveMagazine.PrintWorker"
)
$ErrorActionPreference = "Stop"
if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
throw "Please run this script in an elevated PowerShell window."
}
$existing = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
if (-not $existing) {
Write-Host "Service not found: $ServiceName"
return
}
if ($existing.Status -ne "Stopped") {
Stop-Service -Name $ServiceName -Force
$existing.WaitForStatus("Stopped", "00:00:30")
}
sc.exe delete $ServiceName | Out-Null
Write-Host "Service deleted: $ServiceName"