fix(cua-driver-rs)(windows): cua-driver autostart enable self-elevates for RunLevel=Highest - #1632
Conversation
…s for RunLevel=Highest task #1630 switched the autostart Scheduled Task to RunLevel=Highest, with install.ps1's Register-CuaDriverAutostart self-elevating via Start-Process -Verb RunAs when called from a non-elevated install. But the standalone `cua-driver autostart enable` CLI subcommand did NOT self-elevate — it just called Register-ScheduledTask directly from whatever IL the user's shell was at. From a typical Medium-IL PowerShell, that fails with 0x80070005 (Access is denied) and the user is told to "re-run from an elevated PowerShell", which is friction for what should be a one-command setup. This patch wires the same self-elevation into the Rust CLI: 1. First attempt: register directly. Works for callers already at High IL (install.ps1's elevated child shell, or someone running `cua-driver autostart enable` from an Administrator shell). 2. On access-denied (HRESULT 0x80070005 / "Access is denied" / "requires elevation"), the CLI itself triggers a UAC prompt via PowerShell's Start-Process -Verb RunAs, then runs `cua-driver autostart enable` inside the elevated child. The elevated child hits the first-attempt branch and registers the task cleanly. 3. If the UAC prompt is dismissed, surface a clear actionable error message ("re-run and accept the prompt"). Net UX: `cua-driver autostart enable` from any non-elevated PowerShell triggers a UAC prompt once, registers the Highest task, exits. No manual elevation required. Fixes a regression surfaced during the cuademo fresh-install dogfood. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughWindows scheduled-task registration in the autostart enable path now attempts registration directly and returns success immediately if the PowerShell command succeeds. On failure, it detects elevation-related stderr patterns and spawns an elevated PowerShell process to retry registration from a privileged context, or returns an error if the failure is unrelated to elevation. ChangesWindows Autostart Registration with Self-Elevation
Sequence DiagramsequenceDiagram
participant Driver as Driver Process
participant PS as PowerShell (User)
participant Task as Task Scheduler
participant UAC as Windows UAC
participant ElevPS as PowerShell (Elevated)
Driver->>PS: Execute registration command
PS->>Task: Register scheduled task
Task-->>PS: error: Access Denied
PS-->>Driver: Return stderr with access denied
Driver->>UAC: Request elevation via Start-Process -Verb RunAs
UAC->>ElevPS: User approves → launch elevated PowerShell
ElevPS->>Driver: Re-run autostart enable
Driver->>ElevPS: Execute registration command (elevated)
ElevPS->>Task: Register scheduled task (elevated)
Task-->>ElevPS: Success
ElevPS-->>Driver: exit code 0
Driver-->>Driver: Return Ok()
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
PR #1630 made
install.ps1 -AutoStartself-elevate when registering the autostart task atRunLevel=Highest. But the standalone CLI subcommandcua-driver autostart enablewas left as-is — it just callsRegister-ScheduledTaskdirectly from whatever IL the user's shell is at, which fails with0x80070005 Access is deniedfrom a typical non-admin PowerShell.This patch adds the same self-elevation flow to the Rust CLI: first attempt at current IL, on access-denied trigger a UAC prompt via
Start-Process -Verb RunAsand re-runcua-driver autostart enableinside the elevated child shell.UX before/after
install.ps1 -AutoStartfrom Medium ILcua-driver autostart enablefrom Medium ILcua-driver autostart enablefrom High IL (admin shell)Implementation
crates/cua-driver/src/autostart.rs::enable:0x80070005,"Access is denied","permission","requires elevation"), spawnpowershell -Command "Start-Process -Verb RunAs ..."which fires the UAC prompt and re-invokescua-driver autostart enableinside the elevated child. The elevated child hits branch (1) and registers cleanly.The PowerShell
-Verb RunAsinvocation usesCREATE_NO_WINDOWso the elevated child's console doesn't flash up.Repro / verification
Surfaced during the cuademo fresh-install dogfood: a standard admin user (BUILTIN\Administrators, NOT RID 500, UAC-split-token) ran
cua-driver autostart enablefrom their non-elevated PowerShell and got the0x80070005error. With this patch, the same invocation triggers a UAC prompt → accept → task registered atRunLevel=Highest.cargo check -p cua-driverclean on the VM (11.26s)Related
🤖 Generated with Claude Code
Summary by CodeRabbit