mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
Windows acceptance on the local UTM guest was a pile of one-off commands: finding utmctl, polling async exec, running as the desktop user with a basic token, pinning builds, and pre-seeding the UI cache. utm.sh wraps those steps, manual-setup.ps1 gives a one-line hands-on setup in an isolated home, and the skill records the workflow and the pitfalls hit along the way (S4U tokens, ARM64 emulation, zsh echo). Refs #299
19 lines
1.2 KiB
PowerShell
19 lines
1.2 KiB
PowerShell
# Runs a PowerShell script as the logged-in desktop user through a scheduled task.
|
|
# utmctl exec runs as SYSTEM, which can always create symlinks; this gives the token a real user gets.
|
|
# Usage: launch-task.ps1 -Name <task> -User <name> -Script <ps1> [-ScriptArgs <string>] [-Basic]
|
|
# -Basic wraps the run in `runas /trustlevel:0x20000` (basic-user token: no symlink right).
|
|
# Interactive tasks only start while -User is logged in; S4U gives a different token, so it is not used.
|
|
param(
|
|
[Parameter(Mandatory)] [string]$Name,
|
|
[Parameter(Mandatory)] [string]$User,
|
|
[Parameter(Mandatory)] [string]$Script,
|
|
[string]$ScriptArgs = '',
|
|
[switch]$Basic
|
|
)
|
|
$ps = "powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File $Script $ScriptArgs"
|
|
if ($Basic) { $a = New-ScheduledTaskAction -Execute 'runas.exe' -Argument "/trustlevel:0x20000 `"$ps`"" }
|
|
else { $a = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument ($ps -replace '^powershell\.exe ', '') }
|
|
$p = New-ScheduledTaskPrincipal -UserId $User -LogonType Interactive -RunLevel Limited
|
|
Register-ScheduledTask -TaskName $Name -Action $a -Principal $p -Force | Out-Null
|
|
Start-ScheduledTask -TaskName $Name
|