Privilege split 8/11: The Kurgan's logon task runs without admin rights
- setup.ps1: the elevated part removes the old tasks ("TT LCD Dashboard" and
the elevated "The Kurgan"); back in the unelevated part, setup registers
"The Kurgan" as the user with RunLevel Limited and starts it. Registered
as the user, the tray's "Start with Windows" can change it without admin
rights (checked on this machine with a throwaway task). Running setup.ps1
from an elevated window is refused, since the task must be registered
unelevated. The hardware service's install follows in stage 9.
- kurgan/tray.py: texts for an unelevated task; a failed toggle suggests
re-running setup.ps1 (for a task an older setup registered elevated).
- README: the task is unelevated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e583e25346
commit
a7ebf42838
3 files changed
+58
-45
No files matched your search
@@ -27,7 +27,7 @@ This does the following:
|
|||||||
|
|
||||||
- Installs the Python packages into the project's `.venv` (or for the current user).
|
- Installs the Python packages into the project's `.venv` (or for the current user).
|
||||||
- Installs [PawnIO](https://pawnio.eu). PawnIO is the signed driver LibreHardwareMonitor and FanControl also use. It reads the Intel CPU sensors and drives the motherboard fan headers and the RAM lighting.
|
- Installs [PawnIO](https://pawnio.eu). PawnIO is the signed driver LibreHardwareMonitor and FanControl also use. It reads the Intel CPU sensors and drives the motherboard fan headers and the RAM lighting.
|
||||||
- Replaces the old **TT LCD Dashboard** task with a **The Kurgan** scheduled task. The task runs `pythonw -m kurgan` hidden, with admin rights, at every logon.
|
- Replaces the old **TT LCD Dashboard** task (and an older, elevated **The Kurgan** task) with a **The Kurgan** scheduled task, registered as you. The task runs `pythonw -m kurgan` hidden, without admin rights, at every logon. Run `setup.ps1` from a normal PowerShell window; it asks for admin rights itself.
|
||||||
|
|
||||||
`-RetireAIServices` stops and disables the **Strata Local Service** and **Qwen4 Local Service**
|
`-RetireAIServices` stops and disables the **Strata Local Service** and **Qwen4 Local Service**
|
||||||
tasks, so The Kurgan can run whichever server you select. Without that switch, The Kurgan finds
|
tasks, so The Kurgan can run whichever server you select. Without that switch, The Kurgan finds
|
||||||
@@ -364,7 +364,7 @@ Stop-ScheduledTask "The Kurgan" # only one copy ru
|
|||||||
.\.venv\Scripts\python.exe -m kurgan --preview x.png # render one LCD frame from live sensors
|
.\.venv\Scripts\python.exe -m kurgan --preview x.png # render one LCD frame from live sensors
|
||||||
$env:KURGAN_DATA_DIR = "$env:TEMP\kurgan-demo"
|
$env:KURGAN_DATA_DIR = "$env:TEMP\kurgan-demo"
|
||||||
.\.venv\Scripts\python.exe -m kurgan --demo --port 18080 # simulated hardware; separate settings
|
.\.venv\Scripts\python.exe -m kurgan --demo --port 18080 # simulated hardware; separate settings
|
||||||
Start-ScheduledTask "The Kurgan" # back to the hidden, elevated copy
|
Start-ScheduledTask "The Kurgan" # back to the hidden copy
|
||||||
```
|
```
|
||||||
|
|
||||||
In demo mode the LLM servers use ports 18082 and 18083, but they are real servers.
|
In demo mode the LLM servers use ports 18082 and 18083, but they are real servers.
|
||||||
|
|||||||
+7
-7
@@ -5,12 +5,12 @@ The tooltip shows the power draw; the menu shows each capability's status and ha
|
|||||||
left button opens the web UI directly. notify() shows a balloon tip when something starts
|
left button opens the web UI directly. notify() shows a balloon tip when something starts
|
||||||
going wrong (fan failsafes, AI server errors, failing sensors).
|
going wrong (fan failsafes, AI server errors, failing sensors).
|
||||||
|
|
||||||
"Start with Windows" switches the logon trigger of "The Kurgan" scheduled task (installed by
|
"Start with Windows" switches the logon trigger of "The Kurgan" scheduled task on or off.
|
||||||
setup.ps1) on or off. The task itself stays enabled, so it can still be started by hand,
|
setup.ps1 registers that task as you, without admin rights, so changing it needs none. The task
|
||||||
with admin rights and no UAC prompt: Start-ScheduledTask "The Kurgan"
|
itself stays enabled, so it can still be started by hand: Start-ScheduledTask "The Kurgan"
|
||||||
|
|
||||||
The Kurgan usually runs elevated while Explorer doesn't, so Windows would drop Explorer's
|
If The Kurgan is ever run elevated (it shouldn't be), Windows would drop Explorer's clicks on
|
||||||
clicks on the icon; the window explicitly accepts those messages (ChangeWindowMessageFilterEx).
|
the icon; the window explicitly accepts those messages (ChangeWindowMessageFilterEx).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
@@ -381,8 +381,8 @@ class TrayIcon:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.warning("Couldn't change Start with Windows: %s", e)
|
log.warning("Couldn't change Start with Windows: %s", e)
|
||||||
hint = "" if _is_admin() else (
|
hint = "" if _is_admin() else (
|
||||||
"\n\nChanging this needs admin rights. The Kurgan has them when its startup task "
|
"\n\nIf the task was registered with admin rights (by an older setup.ps1), run "
|
||||||
"starts it (Start-ScheduledTask \"The Kurgan\").")
|
"setup.ps1 again: it registers the task as you, and then this works.")
|
||||||
_u32.MessageBoxW(self._hwnd, f"Couldn't turn Start with Windows {'on' if want else 'off'}.\n\n{e}{hint}",
|
_u32.MessageBoxW(self._hwnd, f"Couldn't turn Start with Windows {'on' if want else 'off'}.\n\n{e}{hint}",
|
||||||
self.title, MB_ICONWARNING | MB_SETFOREGROUND)
|
self.title, MB_ICONWARNING | MB_SETFOREGROUND)
|
||||||
self._refresh_autostart() # show what the task really says now
|
self._refresh_autostart() # show what the task really says now
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
# Sets up The Kurgan:
|
# Sets up The Kurgan:
|
||||||
# 1. installs the Python packages it needs (into the project's .venv if there is one)
|
# 1. installs the Python packages it needs (into the project's .venv if there is one)
|
||||||
# 2. installs PawnIO (signed driver used by LibreHardwareMonitor) for CPU sensors, top fans and RAM lighting
|
# 2. installs PawnIO (signed driver used by LibreHardwareMonitor) for CPU sensors, top fans and RAM lighting
|
||||||
# 3. replaces the old "TT LCD Dashboard" startup task with "The Kurgan" (hidden, admin rights, at logon)
|
# 3. removes the old startup tasks ("TT LCD Dashboard", and "The Kurgan" from when it ran with admin rights)
|
||||||
# 4. with -RetireAIServices: stops and disables the "Strata Local Service" and "Qwen4 Local Service"
|
# 4. with -RetireAIServices: stops and disables the "Strata Local Service" and "Qwen4 Local Service"
|
||||||
# tasks, so The Kurgan runs whichever LLM server you select (re-enable them with uninstall.ps1)
|
# tasks, so The Kurgan runs whichever LLM server you select (re-enable them with uninstall.ps1)
|
||||||
# 5. starts The Kurgan; the web UI is at http://127.0.0.1:8080/
|
# 5. registers "The Kurgan" (hidden, at logon) as you, WITHOUT admin rights, so the tray's
|
||||||
|
# "Start with Windows" can change it, and starts it; the web UI is at http://127.0.0.1:8080/
|
||||||
#
|
#
|
||||||
# Run from a normal PowerShell window:
|
# Run from a normal (not elevated) PowerShell window:
|
||||||
# powershell -ExecutionPolicy Bypass -File .\setup.ps1 [-RetireAIServices]
|
# powershell -ExecutionPolicy Bypass -File .\setup.ps1 [-RetireAIServices]
|
||||||
# It asks for administrator rights (UAC) itself.
|
# It asks for administrator rights (UAC) itself for steps 2-4.
|
||||||
|
|
||||||
param([switch]$Elevated, [string]$PythonW, [switch]$RetireAIServices)
|
param([switch]$Elevated, [switch]$RetireAIServices)
|
||||||
|
|
||||||
$ErrorActionPreference = 'Stop'
|
$ErrorActionPreference = 'Stop'
|
||||||
$TaskName = 'The Kurgan'
|
$TaskName = 'The Kurgan'
|
||||||
@@ -21,6 +22,12 @@ $Here = $PSScriptRoot
|
|||||||
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
$isAdmin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole(
|
||||||
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
[Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||||
|
|
||||||
|
if ($isAdmin -and -not $Elevated) {
|
||||||
|
Write-Host "Run setup.ps1 from a normal PowerShell window, not an elevated one: The Kurgan's startup" -ForegroundColor Red
|
||||||
|
Write-Host "task must be registered as you without admin rights. It asks for admin rights itself." -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
if (-not $isAdmin) {
|
if (-not $isAdmin) {
|
||||||
# Prefer the project's own .venv; otherwise use whichever python is on PATH.
|
# Prefer the project's own .venv; otherwise use whichever python is on PATH.
|
||||||
$venvPython = Join-Path $Here '.venv\Scripts\python.exe'
|
$venvPython = Join-Path $Here '.venv\Scripts\python.exe'
|
||||||
@@ -38,11 +45,39 @@ if (-not $isAdmin) {
|
|||||||
& $python -m pip install @pipArgs --quiet --disable-pip-version-check -r (Join-Path $Here 'requirements.txt')
|
& $python -m pip install @pipArgs --quiet --disable-pip-version-check -r (Join-Path $Here 'requirements.txt')
|
||||||
if ($LASTEXITCODE -ne 0) { throw "pip install failed" }
|
if ($LASTEXITCODE -ne 0) { throw "pip install failed" }
|
||||||
|
|
||||||
Write-Host "Requesting administrator rights for PawnIO and the startup task..." -ForegroundColor Cyan
|
Write-Host "Requesting administrator rights for PawnIO and the old startup tasks..." -ForegroundColor Cyan
|
||||||
$argList = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Elevated -PythonW `"$pythonw`""
|
$argList = "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`" -Elevated"
|
||||||
if ($RetireAIServices) { $argList += ' -RetireAIServices' }
|
if ($RetireAIServices) { $argList += ' -RetireAIServices' }
|
||||||
$p = Start-Process powershell -Verb RunAs -ArgumentList $argList -Wait -PassThru
|
$p = Start-Process powershell -Verb RunAs -ArgumentList $argList -Wait -PassThru
|
||||||
exit $p.ExitCode
|
if ($p.ExitCode -ne 0) { Write-Host "Setup stopped (the elevated part failed)." -ForegroundColor Red; exit $p.ExitCode }
|
||||||
|
|
||||||
|
# --- The Kurgan's startup task: as you, without admin rights --------------------------
|
||||||
|
try {
|
||||||
|
$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||||
|
$action = New-ScheduledTaskAction -Execute $pythonw -Argument '-m kurgan' -WorkingDirectory $Here
|
||||||
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $user
|
||||||
|
$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited
|
||||||
|
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
|
||||||
|
-ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 5 -RestartInterval (New-TimeSpan -Minutes 1) `
|
||||||
|
-MultipleInstances IgnoreNew -StartWhenAvailable
|
||||||
|
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $principal `
|
||||||
|
-Settings $settings -Description 'The Kurgan: LCD dashboard, lighting, the local LLM servers and the web UI' `
|
||||||
|
-Force | Out-Null
|
||||||
|
Start-ScheduledTask -TaskName $TaskName
|
||||||
|
} catch {
|
||||||
|
Write-Host "Registering the startup task failed: $_" -ForegroundColor Red
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Host "Done. '$TaskName' is running and will start at every logon." -ForegroundColor Green
|
||||||
|
Write-Host "Web UI: http://127.0.0.1:8080/ Log: $env:LOCALAPPDATA\Kurgan\kurgan.log"
|
||||||
|
if (-not $RetireAIServices) {
|
||||||
|
$running = $AITasks | Where-Object { (Get-ScheduledTask -TaskName $_ -ErrorAction SilentlyContinue).State -eq 'Running' }
|
||||||
|
if ($running) {
|
||||||
|
Write-Host "Still running on their own: $($running -join ', '). The Kurgan only watches them;" -ForegroundColor Yellow
|
||||||
|
Write-Host "run setup.ps1 -RetireAIServices to let The Kurgan run and swap them." -ForegroundColor Yellow
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function Stop-Matching([scriptblock]$Filter) {
|
function Stop-Matching([scriptblock]$Filter) {
|
||||||
@@ -50,13 +85,8 @@ function Stop-Matching([scriptblock]$Filter) {
|
|||||||
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
|
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- the elevated part ----------------------------------------------------------------------
|
||||||
try {
|
try {
|
||||||
if (-not $PythonW) {
|
|
||||||
$venvPythonW = Join-Path $Here '.venv\Scripts\pythonw.exe'
|
|
||||||
$PythonW = if (Test-Path $venvPythonW) { $venvPythonW } else {
|
|
||||||
Join-Path (Split-Path (Get-Command python -ErrorAction Stop).Source) 'pythonw.exe' }
|
|
||||||
}
|
|
||||||
|
|
||||||
# --- PawnIO -------------------------------------------------------------------------
|
# --- PawnIO -------------------------------------------------------------------------
|
||||||
$pawn = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PawnIO' -ErrorAction SilentlyContinue
|
$pawn = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\PawnIO' -ErrorAction SilentlyContinue
|
||||||
if ($pawn) {
|
if ($pawn) {
|
||||||
@@ -71,7 +101,11 @@ try {
|
|||||||
foreach ($name in $TaskName, $LegacyTaskName) { Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue }
|
foreach ($name in $TaskName, $LegacyTaskName) { Stop-ScheduledTask -TaskName $name -ErrorAction SilentlyContinue }
|
||||||
Stop-Matching { $_.Name -like 'python*.exe' -and ($_.CommandLine -like '*lcd_dashboard.py*' -or
|
Stop-Matching { $_.Name -like 'python*.exe' -and ($_.CommandLine -like '*lcd_dashboard.py*' -or
|
||||||
$_.CommandLine -like '*-m kurgan*') }
|
$_.CommandLine -like '*-m kurgan*') }
|
||||||
Unregister-ScheduledTask -TaskName $LegacyTaskName -Confirm:$false -ErrorAction SilentlyContinue
|
# "The Kurgan" is registered again afterwards, as you and without admin rights (a task
|
||||||
|
# registered elevated couldn't be replaced from there, nor changed by the tray).
|
||||||
|
foreach ($name in $TaskName, $LegacyTaskName) {
|
||||||
|
Unregister-ScheduledTask -TaskName $name -Confirm:$false -ErrorAction SilentlyContinue
|
||||||
|
}
|
||||||
|
|
||||||
# --- the LLM servers' own startup tasks ------------------------------------------------
|
# --- the LLM servers' own startup tasks ------------------------------------------------
|
||||||
if ($RetireAIServices) {
|
if ($RetireAIServices) {
|
||||||
@@ -87,27 +121,6 @@ try {
|
|||||||
($_.Name -eq 'llama-server.exe' -and $_.CommandLine -like '*qwen4-35b-a3b\service\presets.ini*') }
|
($_.Name -eq 'llama-server.exe' -and $_.CommandLine -like '*qwen4-35b-a3b\service\presets.ini*') }
|
||||||
}
|
}
|
||||||
|
|
||||||
# --- scheduled task ------------------------------------------------------------------
|
|
||||||
$user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
||||||
$action = New-ScheduledTaskAction -Execute $PythonW -Argument '-m kurgan' -WorkingDirectory $Here
|
|
||||||
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $user
|
|
||||||
$principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Highest
|
|
||||||
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries `
|
|
||||||
-ExecutionTimeLimit ([TimeSpan]::Zero) -RestartCount 5 -RestartInterval (New-TimeSpan -Minutes 1) `
|
|
||||||
-MultipleInstances IgnoreNew -StartWhenAvailable
|
|
||||||
Register-ScheduledTask -TaskName $TaskName -Action $action -Trigger $trigger -Principal $principal `
|
|
||||||
-Settings $settings -Description 'The Kurgan: LCD dashboard, fans, lighting and the local LLM server' `
|
|
||||||
-Force | Out-Null
|
|
||||||
Start-ScheduledTask -TaskName $TaskName
|
|
||||||
Write-Host "Done. '$TaskName' is running and will start at every logon." -ForegroundColor Green
|
|
||||||
Write-Host "Web UI: http://127.0.0.1:8080/ Log: $env:LOCALAPPDATA\Kurgan\kurgan.log"
|
|
||||||
if (-not $RetireAIServices) {
|
|
||||||
$running = $AITasks | Where-Object { (Get-ScheduledTask -TaskName $_ -ErrorAction SilentlyContinue).State -eq 'Running' }
|
|
||||||
if ($running) {
|
|
||||||
Write-Host "Still running on their own: $($running -join ', '). The Kurgan only watches them;" -ForegroundColor Yellow
|
|
||||||
Write-Host "run setup.ps1 -RetireAIServices to let The Kurgan run and swap them." -ForegroundColor Yellow
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
Write-Host "Setup failed: $_" -ForegroundColor Red
|
Write-Host "Setup failed: $_" -ForegroundColor Red
|
||||||
Read-Host "Press Enter to close"
|
Read-Host "Press Enter to close"
|
||||||
|
|||||||
Reference in new issue
Block a user