Passing a commandline to an elevate:true profile on the commandline doesn't separate args #16894

Open
opened 2026-01-31 05:26:30 +00:00 by claunia · 1 comment
Owner

Originally created by @zadjii-msft on GitHub (Feb 28, 2022).

(from a teams convo)

I bet that

wt --profile "Admin Cmd" -- cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt

would work

[error 2147942402 (0x80070002) when launching `"cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt"']
I ran: wt --profile "Admin Cmd" -- cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt

I think it's still trying to take the whole string and pass to CreateProcess. Is there a way to get it split up?

it might be the fact that when you do have an elevate:true profile, we have to CreateProcess another terminal process, and I bet we're passing the whole bit after -- as a single arg to the elevated wt

Originally created by @zadjii-msft on GitHub (Feb 28, 2022). (from a teams convo) > I bet that > > ``` > wt --profile "Admin Cmd" -- cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt > ``` > > would work > ```[error 2147942402 (0x80070002) when launching `"cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt"']``` > I ran: `wt --profile "Admin Cmd" -- cmd.exe /c D:\os\src\tools\razzle.cmd amd64fre developer_dir D:\Repos\developer\groups\jevansa no_opt` > > I think it's still trying to take the whole string and pass to CreateProcess. Is there a way to get it split up? > it might be the fact that when you do have an `elevate:true` profile, we have to `CreateProcess` another terminal process, and I bet we're passing the whole bit after `--` as a single arg to the elevated wt
claunia added the Help WantedIssue-BugProduct-TerminalPriority-2Area-Commandline labels 2026-01-31 05:26:31 +00:00
Author
Owner

@Fred-Vatin commented on GitHub (Nov 14, 2022):

WT OS
1.15.2874.0 Win 10 x64 pro 21H1 19043.2251

I confirm. Very annoying bug.

My default profile is named PowerShell 7.
My admin profile named PowerShell 7 [admin] is the same but with "elevate": true.

Case 1 [success]

Run a .ps1 in the default profile.
wt.exe --window 0 new-tab --profile "PowerShell 7" pwsh "E:\OneDrive\Mes Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1"

Case 2 [success]

Open a new tab in the admin profile.
wt.exe --window 0 new-tab --profile "PowerShell 7 [admin]"

It works but still opens a new window even when ran from a terminal as admin.

Case 3 [fail]

Run a .ps1 in the admin profile
wt.exe --window 0 new-tab --profile "PowerShell 7 [admin]" pwsh "E:\OneDrive\Mes Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1"

Error thrown
[error 2147942402 (0x80070002) when launching `"pwsh E:\OneDrive\Mes" Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1']


Any workaround to succeed to run .ps1 script in the terminal as admin ?

@Fred-Vatin commented on GitHub (Nov 14, 2022): WT | OS ------------------ | ---- 1.15.2874.0 | Win 10 x64 pro 21H1 19043.2251 I confirm. Very annoying bug. My default profile is named **PowerShell 7**. My admin profile named **PowerShell 7 [admin]** is the same but with `"elevate": true`. ## Case 1 [success] Run a .ps1 in the default profile. `wt.exe --window 0 new-tab --profile "PowerShell 7" pwsh "E:\OneDrive\Mes Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1"` ## Case 2 [success] Open a new tab in the admin profile. `wt.exe --window 0 new-tab --profile "PowerShell 7 [admin]"` It works but still opens a new window even when ran from a terminal as admin. ## Case 3 [fail] Run a .ps1 in the admin profile `wt.exe --window 0 new-tab --profile "PowerShell 7 [admin]" pwsh "E:\OneDrive\Mes Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1"` Error thrown ``[error 2147942402 (0x80070002) when launching `"pwsh E:\OneDrive\Mes" Documents\PowerShell\Scripts\Chemin des profiles pwsh.ps1']`` --- Any workaround to succeed to run .ps1 script in the terminal as admin ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#16894