31 lines
892 B
PowerShell
31 lines
892 B
PowerShell
param(
|
|
[string]$ServiceName = 'AbogadasLitoralScheduler',
|
|
[string]$NssmPath = 'C:\nssm\win64\nssm.exe'
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Test-Admin {
|
|
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
|
|
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
|
|
return $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
}
|
|
|
|
if (-not (Test-Admin)) {
|
|
throw 'Este script requiere PowerShell ejecutado como Administrador.'
|
|
}
|
|
|
|
if (-not (Test-Path $NssmPath)) {
|
|
throw "No se encontro nssm.exe en: $NssmPath"
|
|
}
|
|
|
|
$service = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
|
if (-not $service) {
|
|
Write-Output "El servicio $ServiceName no existe."
|
|
exit 0
|
|
}
|
|
|
|
& $NssmPath stop $ServiceName | Out-Null
|
|
& $NssmPath remove $ServiceName confirm | Out-Null
|
|
Write-Output "Servicio $ServiceName eliminado."
|