29 lines
1.6 KiB
Python
29 lines
1.6 KiB
Python
import base64
|
|
import runpy
|
|
import sys
|
|
from pathlib import Path
|
|
ROOT = Path(__file__).resolve().parents[3]
|
|
term = runpy.run_path(str(ROOT/'tools/pve_term_exec.py'))
|
|
vm = runpy.run_path(str(ROOT/'tools/pve_vm.py'))
|
|
ticket, csrf = term['login']()
|
|
task = 'VDIDeepLatencyReference20261105'
|
|
folder = r'C:\ProgramData\VDI\deep-latency-20261105'
|
|
if sys.argv[1] == 'start':
|
|
encoded = base64.b64encode(Path(__file__).with_name('windows-drag.ps1').read_bytes()).decode()
|
|
ps = r"""$ErrorActionPreference='Stop'; $folder='"""+folder+r"""';
|
|
New-Item -ItemType Directory -Force $folder | Out-Null
|
|
if (Get-ScheduledTask -TaskName '"""+task+r"""' -ErrorAction SilentlyContinue) { throw 'Task already exists' }
|
|
[IO.File]::WriteAllBytes("$folder\drag.ps1",[Convert]::FromBase64String('"""+encoded+r"""'))
|
|
$action=New-ScheduledTaskAction -Execute powershell.exe -Argument "-NoProfile -ExecutionPolicy Bypass -STA -WindowStyle Hidden -File $folder\drag.ps1"
|
|
$principal=New-ScheduledTaskPrincipal -UserId test -LogonType Interactive -RunLevel Limited
|
|
$settings=New-ScheduledTaskSettingsSet -ExecutionTimeLimit (New-TimeSpan -Minutes 10)
|
|
Register-ScheduledTask -TaskName '"""+task+r"""' -Action $action -Principal $principal -Settings $settings | Out-Null
|
|
Start-ScheduledTask -TaskName '"""+task+r"""'
|
|
'Started temporary reference'
|
|
"""
|
|
else:
|
|
ps = "Stop-ScheduledTask -TaskName '"+task+"' -ErrorAction SilentlyContinue; Unregister-ScheduledTask -TaskName '"+task+"' -Confirm:$false -ErrorAction SilentlyContinue; 'Stopped temporary reference'"
|
|
out, err = vm['agent'](ticket, csrf, ['powershell.exe','-NoProfile','-Command',ps])
|
|
print(out)
|
|
if err: raise RuntimeError(err)
|