Skip to content

fix(init): wait for elevated init child on Windows#259

Merged
CalvinAllen merged 1 commit into
mainfrom
fix/path/elevation-wait
May 12, 2026
Merged

fix(init): wait for elevated init child on Windows#259
CalvinAllen merged 1 commit into
mainfrom
fix/path/elevation-wait

Conversation

@CalvinAllen
Copy link
Copy Markdown
Contributor

Summary

Fix the Windows auto-elevation flow in dtvem init so it doesn't falsely
report success when the elevated child didn't actually apply the PATH change.

  • Replace ShellExecute("runas", ...) (fire-and-forget) with
    ShellExecuteEx using SEE_MASK_NOCLOSEPROCESS, then
    WaitForSingleObject + GetExitCodeProcess so the parent can propagate
    the elevated child's result.
  • Forward the original os.Args[1:] (e.g. --user, -y, --verbose)
    to the elevated child instead of hardcoding init. Env vars like
    DTVEM_VERBOSE are inherited automatically by ShellExecuteEx.
  • Detect UAC denial (ERROR_CANCELLED / 1223) and surface a clear error.
  • Re-verify System PATH state after the child exits so a silent
    child-side failure (the init command currently returns on error
    without os.Exit(1)) still produces a parent-side error.

Resolves #252

Test plan

  • On Windows, run dtvem init from a non-admin PowerShell; accept the
    UAC prompt; verify the original session reports success and that
    ~/.dtvem/shims actually lands at the front of the System PATH.
  • Run dtvem init from a non-admin PowerShell and deny the UAC
    prompt; verify the parent surfaces a "UAC prompt canceled" error
    rather than printing "dtvem initialized successfully!".
  • Run dtvem init --user from a non-admin PowerShell; verify the
    elevation path is not taken (User PATH branch) and behavior is
    unchanged.
  • Run dtvem init from an already-elevated PowerShell; verify it
    still modifies System PATH directly without re-launching itself.
  • ./rnr check (format, lint, all tests) passes locally.

Replace fire-and-forget ShellExecute("runas") with ShellExecuteEx
(SEE_MASK_NOCLOSEPROCESS), wait on the returned process handle, and
propagate the child's result to the parent. Also forward the original
command-line args (e.g. --user, --yes) to the elevated child instead of
hardcoding "init", and re-verify System PATH state after the wait so a
silent child failure can't be reported as success.
@CalvinAllen CalvinAllen merged commit f1dfab5 into main May 12, 2026
14 checks passed
@CalvinAllen CalvinAllen deleted the fix/path/elevation-wait branch May 12, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: dtvem init auto-elevation on Windows reports success but fix doesn't take

1 participant