|
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
6 | 6 | import assert from 'assert'; |
7 | | -import { IProcessEnvironment } from '../../../base/common/platform.js'; |
| 7 | +import { dirname, resolve } from '../../../base/common/path.js'; |
| 8 | +import { IProcessEnvironment, isWindows } from '../../../base/common/platform.js'; |
8 | 9 | import { localize } from '../../../nls.js'; |
9 | 10 | import { NativeParsedArgs } from '../common/argv.js'; |
10 | 11 | import { ErrorReporter, NATIVE_CLI_COMMANDS, OPTIONS, parseArgs } from './argv.js'; |
@@ -63,6 +64,17 @@ function stripAppPath(argv: string[]): string[] | undefined { |
63 | 64 | export function parseMainProcessArgv(processArgv: string[]): NativeParsedArgs { |
64 | 65 | let [, ...args] = processArgv; |
65 | 66 |
|
| 67 | + // When code.exe is configured to 'Run as administrator' on Windows, the CLI launcher (code.cmd) sets ELECTRON_RUN_AS_NODE=1 and passes |
| 68 | + // cli.js as the first argument. The elevated process does not inherit the environment variable so Electron starts as a GUI app with cli.js |
| 69 | + // as a stray positional argument. Detect and strip it. The path may include a version subdirectory (e.g., 2ca3b2734b\resources\app\out\cli.js). |
| 70 | + if (isWindows && args.length > 0) { |
| 71 | + const resolvedArg = resolve(args[0]).toLowerCase(); |
| 72 | + const installDir = dirname(process.execPath).toLowerCase() + '\\'; |
| 73 | + if (resolvedArg.startsWith(installDir) && resolvedArg.endsWith('\\resources\\app\\out\\cli.js')) { |
| 74 | + args.shift(); |
| 75 | + } |
| 76 | + } |
| 77 | + |
66 | 78 | // If dev, remove the first non-option argument: it's the app location |
67 | 79 | if (process.env['VSCODE_DEV']) { |
68 | 80 | args = stripAppPath(args) || []; |
|
0 commit comments