start wt.exe with parameter fails in administrator mode #19398

Open
opened 2026-01-31 06:42:07 +00:00 by claunia · 5 comments
Owner

Originally created by @Matzeeee on GitHub (Feb 16, 2023).

Windows Terminal version

1.16.230126001

Windows build number

10.0.19045.2604

Other Software

No response

Steps to reproduce

Open cmd.exe and type "wt ping google.de".
image

Expected Behavior

Open wt with cmd.exe and execute "ping google.de".
image

Actual Behavior

If wt runs with option "run profile as administrator" cmd.exe opens but parameter (ping google.de) is not executed.
image
image

Originally created by @Matzeeee on GitHub (Feb 16, 2023). ### Windows Terminal version 1.16.230126001 ### Windows build number 10.0.19045.2604 ### Other Software _No response_ ### Steps to reproduce Open cmd.exe and type "wt ping google.de". ![image](https://user-images.githubusercontent.com/60921150/219412574-59faacd7-8d11-4719-b67a-745dd5b86725.png) ### Expected Behavior Open wt with cmd.exe and execute "ping google.de". ![image](https://user-images.githubusercontent.com/60921150/219412701-c62d890d-8f60-4792-9978-55e5ff769fda.png) ### Actual Behavior If wt runs with option "run profile as administrator" cmd.exe opens but parameter (ping google.de) is not executed. ![image](https://user-images.githubusercontent.com/60921150/219412885-2de783c8-3836-4ce9-b26a-aab5addb34e6.png) ![image](https://user-images.githubusercontent.com/60921150/219412971-57fd8b57-0a2d-41b0-878a-bf13e701369d.png)
claunia added the Help WantedIssue-BugProduct-TerminalPriority-2Area-Commandline labels 2026-01-31 06:42:08 +00:00
Author
Owner

@zadjii-msft commented on GitHub (Feb 16, 2023):

Welp. Okay that's wacky, unexpected, and tricky to resolve.

  • Your profiles default is set to elevate:true (profiles.defaults, not just the profile that is your default).
  • When you do wt ping 8.8.8.8, the Terminal opens, and tries to run with all your profiles.default profile's settings, except with the commandline explicitly set to pint 8.8.8.8.
  • After evaluating the settings, Terminal determines this new tab should be run elevated (in accordance with your settings) and then ShellExectute's itself, passing in the profile it should use to spawn the new tab.
    • In this step, it does NOT pass that overwritten commandline along
  • The elevated terminal spawns, and just uses the default commandline for the profile it was told (which was just profiles.defaults)

This one's tricky. We basically need to pick something sensible to happen here. The argument could probably go either way:

  • Should the terminal open elevated, running ping 8.8.8.8?
  • Or should it open unelevated?

I'd lean towards the second. Does that make sense to you @Matzeeee?


In that case, we'd want to modify ShouldImmediatelyHandoffToElevated / _maybeElevate in TerminalPage to ensure that the commandline is the same as the profile, before we decide to just elevate.

@zadjii-msft commented on GitHub (Feb 16, 2023): Welp. Okay that's wacky, unexpected, and tricky to resolve. * Your profiles default is set to `elevate:true` (`profiles.defaults`, not just the profile that is your default). * When you do `wt ping 8.8.8.8`, the Terminal opens, and tries to run with all your `profiles.default` profile's settings, except with the commandline explicitly set to `pint 8.8.8.8`. * After evaluating the settings, Terminal determines this new tab should be run elevated (in accordance with your settings) and then ShellExectute's itself, passing in the profile it should use to spawn the new tab. * In this step, it does NOT pass that overwritten commandline along * The elevated terminal spawns, and just uses the default commandline for the profile it was told (which was just profiles.defaults) This one's tricky. We basically need to pick something sensible to happen here. The argument could probably go either way: * Should the terminal open elevated, running `ping 8.8.8.8`? * Or should it open unelevated? I'd lean towards the second. Does that make sense to you @Matzeeee? <hr> In that case, we'd want to modify `ShouldImmediatelyHandoffToElevated` / `_maybeElevate` in `TerminalPage` to ensure that the commandline is the same as the profile, before we decide to just elevate.
Author
Owner

@Matzeeee commented on GitHub (Feb 16, 2023):

This one's tricky. We basically need to pick something sensible to happen here. The argument could probably go either way:

  • Should the terminal open elevated, running ping 8.8.8.8?
  • Or should it open unelevated?

I'd lean towards the second. Does that make sense to you @Matzeeee?

In that case, we'd want to modify ShouldImmediatelyHandoffToElevated / _maybeElevate in TerminalPage to ensure that the commandline is the same as the profile, before we decide to just elevate.

I expected the terminal to start elevated and then execute the command.

@Matzeeee commented on GitHub (Feb 16, 2023): > This one's tricky. We basically need to pick something sensible to happen here. The argument could probably go either way: > > * Should the terminal open elevated, running `ping 8.8.8.8`? > * Or should it open unelevated? > > I'd lean towards the second. Does that make sense to you @Matzeeee? > > In that case, we'd want to modify `ShouldImmediatelyHandoffToElevated` / `_maybeElevate` in `TerminalPage` to ensure that the commandline is the same as the profile, before we decide to just elevate. I expected the terminal to start elevated and then execute the command.
Author
Owner

@zadjii-msft commented on GitHub (May 5, 2023):

You know, we might be able to something like #15286 for this. Pre-evaluate the actual commandline, given the NewTerminalArgs, and pass that in to elevate-shim.

I'd worry about escaping that commandline though. That'd be scary.

@zadjii-msft commented on GitHub (May 5, 2023): You know, we might be able to something like #15286 for this. Pre-evaluate the actual commandline, given the NewTerminalArgs, and pass that in to elevate-shim. I'd worry about escaping that commandline though. That'd be scary.
Author
Owner

@Matzeeee commented on GitHub (Dec 16, 2024):

will this ever be fixed?

@Matzeeee commented on GitHub (Dec 16, 2024): will this ever be fixed?
Author
Owner

@lhecker commented on GitHub (Dec 17, 2024):

It seems it partially was fixed: wt pwsh now properly spawns PowerShell in an elevated tab. However, it seems something's wrong with parameter escaping, as mentioned above, because the entire commandline given to wt is passed as a "single argument string" that is interpreted as a command line path with spaces. Example:

Image

I'll keep this tab open and look into it after the holidays.

@lhecker commented on GitHub (Dec 17, 2024): It seems it partially was fixed: `wt pwsh` now properly spawns PowerShell in an elevated tab. However, it seems something's wrong with parameter escaping, as mentioned above, because the entire commandline given to `wt` is passed as a `"single argument string"` that is interpreted as a command line path with spaces. Example: ![Image](https://github.com/user-attachments/assets/46e90269-03e0-4400-9b28-579e16b1f77c) I'll keep this tab open and look into it after the holidays.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19398