F
fu.ling-lang.org
↓ 0 downloadsทะเบียนแพ็กเกจ fu.ling-lang.org — เขียนด้วยภาษา Ling (ไทย) ทั้งหมด
Keywords registry, packages, web, ling, thai
lingfu install fu.ling-lang.orgCode / Files (22)
install-service.ps1
# install-service.ps1 — install fu.ling-lang.org as a boot-start, auto-restarting
# background service (implemented as a SYSTEM-level scheduled task, the native
# equivalent of a Windows service without third-party tools like nssm).
#
# Run it once: right-click -> "Run with PowerShell", or from an elevated shell:
# powershell -ExecutionPolicy Bypass -File install-service.ps1
# It self-elevates (UAC prompt) if not already Administrator.
$ErrorActionPreference = 'Stop'
$TaskName = 'fu.ling-lang.org'
$Proj = 'C:\Users\User\Programs\linglibs.ling-lang.org'
$Vbs = Join-Path $Proj 'run_hidden.vbs'
# ── Self-elevate ─────────────────────────────────────────────────────────────
$admin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if (-not $admin) {
Write-Host "Requesting administrator rights..."
Start-Process powershell.exe -Verb RunAs `
-ArgumentList ('-NoProfile -ExecutionPolicy Bypass -File "' + $PSCommandPath + '"')
return
}
# ── Register the service (SYSTEM, at boot, auto-restart on failure) ───────────
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
$action = New-ScheduledTaskAction -Execute 'wscript.exe' `
-Argument ('"' + $Vbs + '"') -WorkingDirectory $Proj
$trigger = New-ScheduledTaskTrigger -AtStartup
$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' `
-LogonType ServiceAccount -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet `
-RestartCount 999 -RestartInterval (New-TimeSpan -Minutes 1) `
-ExecutionTimeLimit ([TimeSpan]::Zero) `
-AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
-MultipleInstances IgnoreNew -StartWhenAvailable
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger `
-Principal $principal -Settings $settings `
-Description 'fu.ling-lang.org Ling package registry — boot-start, auto-restart' | Out-Null
# Avoid a double-launch: the per-user Startup shortcut is now redundant.
$lnk = Join-Path ([Environment]::GetFolderPath('Startup')) 'fu.ling-lang.org.lnk'
if (Test-Path $lnk) { Remove-Item $lnk -Force; Write-Host "Removed redundant Startup shortcut." }
# Start it now and report.
Get-Process ling -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
Start-ScheduledTask -TaskName $TaskName
Start-Sleep -Seconds 6
$srv = Get-Process ling -ErrorAction SilentlyContinue
Write-Host ""
Write-Host ("Service '$TaskName' installed. Running as SYSTEM at boot, auto-restart on failure.")
if ($srv) { Write-Host (" ling.exe PID: " + $srv.Id + " -> http://localhost:6688") }
else { Write-Host " (server not detected yet; check server.log)" }
Write-Host "Manage it in Task Scheduler, or: schtasks /End /TN `"$TaskName`" / /Run / /Delete"