Skip to content

Comments

Remove cli.js argument when running as administrator on Windows#296690

Merged
joaomoreno merged 5 commits intomainfrom
dev/dmitriv/windows-admin-command
Feb 23, 2026
Merged

Remove cli.js argument when running as administrator on Windows#296690
joaomoreno merged 5 commits intomainfrom
dev/dmitriv/windows-admin-command

Conversation

@dmitrivMS
Copy link
Contributor

@dmitrivMS dmitrivMS commented Feb 21, 2026

Fixes #91613

Changes
Ignore the first cli.js argument on Windows when its full path matches one under VS Code installation location.

Notes
with this change commands like "code ." will work and elevated VS Code will open the folder without opening cli.js. This change does not elevate the CLI and it still won't run in this scenario - if elevated CLI is needed, the command needs to be ran from an elevated command prompt.

Validation
With official build and VS Code set to run in admin mode, verified starting VS Code from non-elevated command line does not open cli.js but opens the folder passed in.

@dmitrivMS dmitrivMS added this to the February 2026 milestone Feb 21, 2026
@dmitrivMS dmitrivMS self-assigned this Feb 21, 2026
@dmitrivMS dmitrivMS added windows VS Code on Windows issues workbench-run-as-admin Issues concerning running as administrator labels Feb 21, 2026
Copilot AI review requested due to automatic review settings February 21, 2026 05:11
@dmitrivMS dmitrivMS changed the title fix: handle stray cli.js argument when running as administrator on Wi… Remove cli.js argument when running as administrator on Windows Feb 21, 2026
Copy link
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 fixes a Windows-specific issue where cli.js appears as a stray argument when VS Code is configured to run as administrator. The issue occurs because the CLI launcher (code.cmd) sets the ELECTRON_RUN_AS_NODE=1 environment variable, but when the process is elevated, the environment variable is not inherited. This causes Electron to start as a GUI application with cli.js as an unintended positional argument.

Changes:

  • Added logic to detect and strip the stray cli.js argument on Windows before parsing command-line arguments
  • Added necessary imports for path manipulation (dirname, resolve) and platform detection (isWindows)

@dhtzs
Copy link

dhtzs commented Feb 21, 2026

Thank you for doing this!

@dmitrivMS dmitrivMS marked this pull request as ready for review February 22, 2026 02:47
@dmitrivMS dmitrivMS requested a review from joaomoreno February 22, 2026 02:48
@vs-code-engineering
Copy link

vs-code-engineering bot commented Feb 22, 2026

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@bpasero

Matched files:

  • src/vs/platform/environment/node/argvHelper.ts

@joaomoreno joaomoreno merged commit d311bc9 into main Feb 23, 2026
19 checks passed
@joaomoreno joaomoreno deleted the dev/dmitriv/windows-admin-command branch February 23, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

windows VS Code on Windows issues workbench-run-as-admin Issues concerning running as administrator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: Code opening cli.js when run as Administrator

3 participants