# register-boot-task.ps1 # Registers the VignettePublicRuntime scheduled task to run at user logon # (hidden window). The boot script (scripts/boot-public-runtime.ps1) does the # actual recovery. Re-run to refresh (-Force). Remove with: # Unregister-ScheduledTask -TaskName VignettePublicRuntime -Confirm:$false # # powershell -NoProfile -ExecutionPolicy Bypass -File scripts\register-boot-task.ps1 $ErrorActionPreference = "Stop" $TaskName = "VignettePublicRuntime" $BootScript = "D:\workspace\vignette\scripts\boot-public-runtime.ps1" $UserName = "$env:USERDOMAIN\$env:USERNAME" if (-not (Test-Path -LiteralPath $BootScript)) { throw "boot script not found: $BootScript" } $action = New-ScheduledTaskAction ` -Execute "powershell.exe" ` -Argument ("-NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File `"" + $BootScript + "`"") $trigger = New-ScheduledTaskTrigger -AtLogOn -User $UserName # Interactive: runs in the user session (Start-Process hidden window / Docker Desktop GUI work). # Limited: no admin rights needed. $principal = New-ScheduledTaskPrincipal ` -UserId $env:USERNAME ` -LogonType Interactive ` -RunLevel Limited $settings = New-ScheduledTaskSettingsSet ` -AllowStartIfOnBatteries ` -DontStopIfGoingOnBatteries ` -StartWhenAvailable ` -ExecutionTimeLimit (New-TimeSpan -Minutes 15) Register-ScheduledTask ` -TaskName $TaskName ` -Action $action ` -Trigger $trigger ` -Principal $principal ` -Settings $settings ` -Description "Vignette public runtime auto-recovery (Docker + postgres + engine/api + cloudflared) at logon" ` -Force | Out-Null $task = Get-ScheduledTask -TaskName $TaskName Write-Output ("Registered : " + $TaskName) Write-Output ("State : " + $task.State) Write-Output ("User : " + $principal.UserId) Write-Output ("Trigger : AtLogOn (" + $UserName + ")") Write-Output ("Command : " + $action.Execute + " " + $action.Argument) Write-Output "" Write-Output ("Run now : powershell -NoProfile -ExecutionPolicy Bypass -File " + $BootScript) Write-Output ("Unregister : Unregister-ScheduledTask -TaskName " + $TaskName + " -Confirm:`$false")