| 123456789101112131415161718192021222324252627282930313233 |
- param(
- [ValidateSet('live','demo')][string]$Mode='live',
- [string]$ReleaseRoot='C:\Users\Administrator\delivery\XJKJ-STL-Qt-Clean-0.8.1.12'
- )
- $ErrorActionPreference='Stop'
- $taskName = if ($Mode -eq 'live') {'XJKJ-Qt-Dev-Live'} else {'XJKJ-Qt-Dev-Demo'}
- $script = if ($Mode -eq 'live') {'run_windows_live.ps1'} else {'launch_windows_demo.ps1'}
- $targetScript = Join-Path $ReleaseRoot $script
- if (!(Test-Path -LiteralPath $targetScript)) { throw "Missing $targetScript" }
- $scheduler = New-Object -ComObject 'Schedule.Service'
- $scheduler.Connect()
- $folder = $scheduler.GetFolder('\')
- $definition = $scheduler.NewTask(0)
- $definition.RegistrationInfo.Description = 'Latest XJKJ-STL Qt dev build on the interactive desktop'
- $definition.Principal.UserId = $env:COMPUTERNAME + '\Administrator'
- $definition.Principal.LogonType = 3
- $definition.Principal.RunLevel = 1
- $definition.Settings.Enabled = $true
- $definition.Settings.AllowDemandStart = $true
- $definition.Settings.StopIfGoingOnBatteries = $false
- $definition.Settings.DisallowStartIfOnBatteries = $false
- # The real demo is intended to stay visible indefinitely. Never give the
- # desktop launcher a short scheduler deadline that might kill its GUI child.
- $definition.Settings.ExecutionTimeLimit = if ($Mode -eq 'live') {'PT20M'} else {'PT0S'}
- $definition.Settings.AllowHardTerminate = $false
- $action = $definition.Actions.Create(0)
- $action.Path = "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"
- $action.Arguments = '-NoProfile -ExecutionPolicy Bypass -File "' + $targetScript + '" -ReleaseRoot "' + $ReleaseRoot + '"'
- $action.WorkingDirectory = $ReleaseRoot
- $folder.RegisterTaskDefinition($taskName,$definition,6,$null,$null,3,$null) | Out-Null
- $registered = $folder.GetTask($taskName)
- $running = $registered.Run($null)
- Write-Output ('task=' + $taskName + ' user=' + [Security.Principal.WindowsIdentity]::GetCurrent().Name + ' instance=' + $running.InstanceGuid)
|