Add service install/uninstall scripts to repo root
This commit is contained in:
parent
fcddfe215a
commit
3182ef655e
3 changed files with 75 additions and 0 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -3,6 +3,10 @@ bin/
|
||||||
obj/
|
obj/
|
||||||
publish/
|
publish/
|
||||||
|
|
||||||
|
# Skripte aus publish/ im Root behalten
|
||||||
|
!install-service.ps1
|
||||||
|
!uninstall-service.ps1
|
||||||
|
|
||||||
# Visual Studio
|
# Visual Studio
|
||||||
.vs/
|
.vs/
|
||||||
*.user
|
*.user
|
||||||
|
|
|
||||||
42
install-service.ps1
Normal file
42
install-service.ps1
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
|
$ServiceName = "MailPrint"
|
||||||
|
$DisplayName = "MailPrint - E-Mail & WebAPI zu Drucker"
|
||||||
|
$Description = "Druckt PDF-Anhaenge automatisch aus E-Mails (IMAP/POP3) und per REST API auf Windows-Drucker."
|
||||||
|
$ExePath = Join-Path $PSScriptRoot "publish\MailPrint.exe"
|
||||||
|
|
||||||
|
if (-not (Test-Path $ExePath)) {
|
||||||
|
Write-Error "MailPrint.exe nicht gefunden: $ExePath"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
$existing = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if ($existing) {
|
||||||
|
Write-Host "Dienst '$ServiceName' ist bereits installiert. Stoppe zuerst..." -ForegroundColor Yellow
|
||||||
|
Stop-Service -Name $ServiceName -Force -ErrorAction SilentlyContinue
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Installiere Dienst '$ServiceName'..." -ForegroundColor Cyan
|
||||||
|
|
||||||
|
New-Service `
|
||||||
|
-Name $ServiceName `
|
||||||
|
-DisplayName $DisplayName `
|
||||||
|
-Description $Description `
|
||||||
|
-BinaryPathName $ExePath `
|
||||||
|
-StartupType Automatic | Out-Null
|
||||||
|
|
||||||
|
sc.exe failure $ServiceName reset= 3600 actions= restart/5000/restart/10000/restart/30000 | Out-Null
|
||||||
|
|
||||||
|
Write-Host "Starte Dienst..." -ForegroundColor Cyan
|
||||||
|
Start-Service -Name $ServiceName
|
||||||
|
|
||||||
|
$svc = Get-Service -Name $ServiceName
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Ergebnis:" -ForegroundColor Green
|
||||||
|
Write-Host " Name: $($svc.Name)"
|
||||||
|
Write-Host " Status: $($svc.Status)"
|
||||||
|
Write-Host " Start: $($svc.StartType)"
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Fertig. MailPrint laeuft jetzt als Windows-Dienst." -ForegroundColor Green
|
||||||
|
Write-Host "Logs: $(Join-Path $PSScriptRoot 'publish\logs')"
|
||||||
29
uninstall-service.ps1
Normal file
29
uninstall-service.ps1
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
#Requires -RunAsAdministrator
|
||||||
|
|
||||||
|
$ServiceName = "MailPrint"
|
||||||
|
|
||||||
|
$svc = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if (-not $svc) {
|
||||||
|
Write-Host "Dienst '$ServiceName' ist nicht installiert." -ForegroundColor Yellow
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($svc.Status -ne "Stopped") {
|
||||||
|
Write-Host "Stoppe Dienst '$ServiceName'..." -ForegroundColor Cyan
|
||||||
|
Stop-Service -Name $ServiceName -Force
|
||||||
|
Start-Sleep -Seconds 3
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "Entferne Dienst '$ServiceName'..." -ForegroundColor Cyan
|
||||||
|
sc.exe delete $ServiceName | Out-Null
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 2
|
||||||
|
|
||||||
|
$check = Get-Service -Name $ServiceName -ErrorAction SilentlyContinue
|
||||||
|
if ($check) {
|
||||||
|
Write-Error "Dienst konnte nicht entfernt werden. Bitte manuell pruefen."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Dienst '$ServiceName' erfolgreich deinstalliert." -ForegroundColor Green
|
||||||
Loading…
Add table
Add a link
Reference in a new issue