mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-04 20:36:01 +01:00
Remove cli.js argument when running as administrator on Windows (#296690)
* fix: handle stray cli.js argument when running as administrator on Windows * Handle version subdirectory.
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import assert from 'assert';
|
||||
import { IProcessEnvironment } from '../../../base/common/platform.js';
|
||||
import { dirname, resolve } from '../../../base/common/path.js';
|
||||
import { IProcessEnvironment, isWindows } from '../../../base/common/platform.js';
|
||||
import { localize } from '../../../nls.js';
|
||||
import { NativeParsedArgs } from '../common/argv.js';
|
||||
import { ErrorReporter, NATIVE_CLI_COMMANDS, OPTIONS, parseArgs } from './argv.js';
|
||||
@@ -63,6 +64,17 @@ function stripAppPath(argv: string[]): string[] | undefined {
|
||||
export function parseMainProcessArgv(processArgv: string[]): NativeParsedArgs {
|
||||
let [, ...args] = processArgv;
|
||||
|
||||
// When code.exe is configured to 'Run as administrator' on Windows, the CLI launcher (code.cmd) sets ELECTRON_RUN_AS_NODE=1 and passes
|
||||
// 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
|
||||
// as a stray positional argument. Detect and strip it. The path may include a version subdirectory (e.g., 2ca3b2734b\resources\app\out\cli.js).
|
||||
if (isWindows && args.length > 0) {
|
||||
const resolvedArg = resolve(args[0]).toLowerCase();
|
||||
const installDir = dirname(process.execPath).toLowerCase() + '\\';
|
||||
if (resolvedArg.startsWith(installDir) && resolvedArg.endsWith('\\resources\\app\\out\\cli.js')) {
|
||||
args.shift();
|
||||
}
|
||||
}
|
||||
|
||||
// If dev, remove the first non-option argument: it's the app location
|
||||
if (process.env['VSCODE_DEV']) {
|
||||
args = stripAppPath(args) || [];
|
||||
|
||||
Reference in New Issue
Block a user