# Level Screen Recorder – Deploy LevelScreenRecorder_KeepAlive scheduled task (User-Profile install) # Run in user context (e.g. GPO User Configuration → Scripts → Logon, or MDM) so the task is created for each user. # Usage: .\deploy-keepalive-task-userprofile.ps1 # Place this script and LevelScreenRecorder_KeepAlive-peruser.xml.template in the same folder. $ErrorActionPreference = "Stop" $sid = ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value if (-not $sid) { Write-Error "Could not get current user SID." exit 1 } $scriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Path } $templateName = "LevelScreenRecorder_KeepAlive-peruser.xml.template" $templatePath = Join-Path $scriptDir $templateName if (-not (Test-Path -LiteralPath $templatePath)) { Write-Error "Template not found: $templatePath. Copy this script and $templateName to the same folder." exit 1 } $xmlContent = [System.IO.File]::ReadAllText($templatePath) $xmlContent = $xmlContent.Replace('__USER_SID__', $sid) $tempPath = [System.IO.Path]::GetTempFileName() try { [System.IO.File]::WriteAllText($tempPath, $xmlContent, [System.Text.Encoding]::Unicode) $result = & schtasks /create /tn LevelScreenRecorder_KeepAlive /xml $tempPath /f 2>&1 if ($LASTEXITCODE -ne 0) { Write-Error "schtasks failed: $result" exit 1 } Write-Host "LevelScreenRecorder_KeepAlive task created for current user (User-Profile)." } finally { if (Test-Path -LiteralPath $tempPath) { Remove-Item -LiteralPath $tempPath -Force -ErrorAction SilentlyContinue } }