45 lines
2.3 KiB
PowerShell
45 lines
2.3 KiB
PowerShell
# ==================================================================
|
|
# SAP-ERP Portal - autostart installer (called by install-autostart.bat)
|
|
# Registers a Task-Scheduler task that starts the portal at every
|
|
# Windows boot (as SYSTEM, hidden), and starts it right now.
|
|
# ==================================================================
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
# must be admin
|
|
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
|
|
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
|
if (-not $isAdmin) {
|
|
Write-Host 'This script must be run as Administrator.' -ForegroundColor Red
|
|
Write-Host 'Right-click install-autostart.bat and choose "Run as administrator".'
|
|
exit 1
|
|
}
|
|
|
|
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$vbs = Join-Path $here 'run-hidden.vbs'
|
|
if (-not (Test-Path $vbs)) { Write-Host "Missing: $vbs" -ForegroundColor Red; exit 1 }
|
|
|
|
Write-Host 'Creating scheduled task "SAP-ERP-Portal"...'
|
|
$action = New-ScheduledTaskAction -Execute 'wscript.exe' -Argument ('"{0}"' -f $vbs)
|
|
$trigger = New-ScheduledTaskTrigger -AtStartup
|
|
$principal = New-ScheduledTaskPrincipal -UserId 'SYSTEM' -LogonType ServiceAccount -RunLevel Highest
|
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 3 -RestartInterval (New-TimeSpan -Minutes 1)
|
|
|
|
Register-ScheduledTask -TaskName 'SAP-ERP-Portal' -Action $action -Trigger $trigger `
|
|
-Principal $principal -Settings $settings -Force | Out-Null
|
|
|
|
Write-Host 'Starting the portal now...'
|
|
Start-ScheduledTask -TaskName 'SAP-ERP-Portal'
|
|
Start-Sleep -Seconds 4
|
|
|
|
$state = (Get-ScheduledTask -TaskName 'SAP-ERP-Portal').State
|
|
Write-Host ''
|
|
Write-Host "Task state: $state"
|
|
$node = Get-CimInstance Win32_Process | Where-Object { $_.Name -eq 'node.exe' -and $_.CommandLine -match 'server\.js' }
|
|
if ($node) { Write-Host ("Portal RUNNING - node PID " + ($node.ProcessId -join ', ')) -ForegroundColor Green }
|
|
else { Write-Host 'Portal process not detected yet - check logs\server.log & logs\supervisor.log' -ForegroundColor Yellow }
|
|
Write-Host ''
|
|
Write-Host 'Done. The portal now starts automatically with Windows.'
|
|
Write-Host 'Check anytime with deploy\status.bat'
|
|
exit 0
|