Skip to content

Fix PATH for correct user when per-user installer is run as administrator#3048

Merged
jmcouffin merged 2 commits intodevelopfrom
installer-behavior-when-user-is-admin-and-install-per-user
Feb 1, 2026
Merged

Fix PATH for correct user when per-user installer is run as administrator#3048
jmcouffin merged 2 commits intodevelopfrom
installer-behavior-when-user-is-admin-and-install-per-user

Conversation

@jmcouffin
Copy link
Copy Markdown
Contributor

@jmcouffin jmcouffin commented Feb 1, 2026

Per-user installers (pyRevit_*_signed.exe and pyRevit_CLI_*_signed.exe) write the install path to HKCU\Environment\Path. When the user runs the installer "Run as administrator", the process runs elevated and HKCU refers to the elevated user's registry, so PATH is updated only for the admin account and pyrevit is not found in a normal (non-admin) command prompt.

Changes

  • pyrevit.iss and pyrevit-cli.iss: Added Check: NotAdmin to the [Registry] PATH entry so the HKCU write runs only when the installer is not elevated. When the installer is elevated (IsAdmin), CurStepChanged(ssPostInstall) uses ExecAsOriginalUser to run PowerShell and append {app}\bin to the original (logged-in) user's PATH. Added a short comment in the Registry section explaining this.

Result

Running the per-user CLI or full pyRevit installer as administrator now updates PATH for the user who started the installer, so pyrevit works in a regular (non-admin) cmd. Normal (non-elevated) installs are unchanged.

  • Added logic to conditionally update the user PATH variable only when not running as an admin.
  • Implemented a new function to execute PowerShell commands as the original user to ensure proper PATH updates.
  • Updated registry settings to prevent multiple installations from incorrectly modifying the PATH for elevated users.

- Added logic to conditionally update the user PATH variable only when not running as an admin.
- Implemented a new function to execute PowerShell commands as the original user to ensure proper PATH updates.
- Updated registry settings to prevent multiple installations from incorrectly modifying the PATH for elevated users.
@jmcouffin jmcouffin self-assigned this Feb 1, 2026
@jmcouffin jmcouffin requested a review from Copilot February 1, 2026 13:53
@jmcouffin jmcouffin added the Installer Issues related to the pyRevit installer [subsystem] label Feb 1, 2026
Copy link
Copy Markdown
Contributor

@devloai devloai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary:

This PR enhances environment variable handling in pyRevit installer scripts to properly manage PATH updates when installers run with elevated admin privileges. Key changes:

  • Adds conditional logic to skip Registry-based PATH updates for admin users
  • Implements ExecAsOriginalUser to execute PowerShell commands as the original user
  • Prevents elevated installations from incorrectly modifying the admin user's PATH instead of the actual user's PATH

Review Summary:

Reviewed installer scripts for proper PATH handling with admin privileges. The approach of using ExecAsOriginalUser for elevated installations is correct and addresses a real issue where admin-elevated installers would modify the wrong user's environment. However, identified critical PATH duplication bugs that will cause repeated PATH entries on reinstalls/updates, plus silent failure handling that could confuse users.

Critical issues found:

  • Both PowerShell and Registry PATH updates lack duplicate checking, causing PATH pollution on every reinstall
  • Silent failures provide no user notification when PATH updates fail

All comments include actionable fixes with code examples.

Follow-up suggestions:

  • @devloai fix the PATH duplication issues in both installer files
  • @devloai add duplicate checking to prevent PATH pollution on reinstalls

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request addresses a critical issue where per-user installers (pyRevit_*_signed.exe and pyRevit_CLI_*_signed.exe) incorrectly update the PATH environment variable when run with administrator privileges. When elevated, HKCU points to the administrator's registry instead of the actual user's, causing the pyrevit command to be unavailable in non-elevated command prompts.

Changes:

  • Modified installer scripts to conditionally update PATH based on elevation status
  • Added PowerShell-based PATH update mechanism for elevated installations using ExecAsOriginalUser
  • Introduced NotAdmin check function to prevent registry writes when running elevated

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
release/pyrevit.iss Added NotAdmin check to Registry PATH entry, implemented CurStepChanged procedure to update PATH via PowerShell when running as admin
release/pyrevit-cli.iss Identical changes to pyrevit.iss - added NotAdmin check and PowerShell-based PATH update for elevated installations

- Renamed function to improve clarity and added logic to check if the PATH variable already includes the application path before updating.
- Enhanced error handling to notify users if the installer fails to update the user PATH environment variable.
- Updated registry settings to ensure proper PATH modifications only occur when not running as an admin.
@jmcouffin jmcouffin changed the title Enhance environment variable handling in installer scripts Fix PATH for correct user when per-user installer is run as administrator Feb 1, 2026
@jmcouffin jmcouffin merged commit 6deb70b into develop Feb 1, 2026
@jmcouffin jmcouffin deleted the installer-behavior-when-user-is-admin-and-install-per-user branch February 1, 2026 14:29
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1433-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1538-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1543-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1553-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1612-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1624-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1738-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1743-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1829-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 5.3.1.26032+1937-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 6.0.0.26032+1956-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 6.0.0.26032+2005-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New work-in-progress (wip) builds are available for 6.0.0.26032+2008-wip

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New public release are available for 6.0.0.26032+2040

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 1, 2026

📦 New public release are available for 6.0.0.26032+2040

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Installer Issues related to the pyRevit installer [subsystem]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants