# Install-GeoVLogSvc.ps1 param ( [string]$ExePath = "$PSScriptRoot\..\bin\Release\net8.0-windows\GeoVLogSvc.exe", [string]$ServiceName = "GeoVLogSvc", [string]$DisplayName = "GeoVLog Sensor Logger", [string]$Description = "Logs flight sensor data to HDF5 and encrypts the manifest on shutdown.", [int]$PreShutdownTimeoutMS = 60000 # 60 seconds ) function Ensure-Admin { if (-not ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Error "⚠ This script must be run as Administrator!" exit 1 } } function Create-Service { Write-Host "πŸ”§ Creating service '$ServiceName'..." sc.exe create $ServiceName binPath= "`"$ExePath`"" start= delayed-auto DisplayName= "`"$DisplayName`"" sc.exe description $ServiceName "$Description" sc.exe failure $ServiceName reset= 86400 actions= restart/5000/restart/10000/restart/60000 sc.exe sidtype $ServiceName unrestricted } function Set-PreShutdownTimeout { $regPath = "HKLM:\SYSTEM\CurrentControlSet\Services\$ServiceName" if (-not (Test-Path $regPath)) { Write-Warning "❗Service registry key not found, cannot set PreShutdownTimeout." return } Set-ItemProperty -Path $regPath -Name PreshutdownTimeout -Value $PreShutdownTimeoutMS -Type DWord Write-Host "πŸ•’ PreShutdownTimeout set to $PreShutdownTimeoutMS ms" } function Register-EventLogSource { if (-not [System.Diagnostics.EventLog]::SourceExists($ServiceName)) { New-EventLog -LogName Application -Source $ServiceName Write-Host "πŸ“ Registered EventLog source: $ServiceName" } else { Write-Host "βœ… EventLog source already exists." } } function Start-ServiceSafe { Write-Host "πŸš€ Starting service..." Start-Service -Name $ServiceName } Ensure-Admin Create-Service Set-PreShutdownTimeout Register-EventLogSource Start-ServiceSafe Write-Host "`nβœ… Service '$ServiceName' installed and running successfully."