Skip to content

Targeting current instance with "-w 0" command line doesn't work if running as administrator #9628

Open

Description

Windows Terminal version (or Windows build number)

1.7.572.0

Other Software

No response

Steps to reproduce

Launch Windows Terminal as administrator
Run the command line: wt -w 0 nt

Expected Behavior

This should open a new tab in the current window

Actual Behavior

Launches a new instance of Windows Terminal

It would make sense that I wouldn't be able to send commands to other WT windows that were running as admin, but running a command specifically targeting the current window should still work (as a special case if necessary).

Activity

  1. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Mar 26, 2021
  2. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Mar 26, 2021
  3. zadjii-msft commented on Mar 26, 2021

    @zadjii-msft
    Member

    Weird, because I definitely can't repro this locally. Michael Niksa (@miniksa) Do you know if there's a way I could have David Jackman (@DJackman123) here collect the events emitted to a particular tracelogging GUID and send them to me? That is what all that logging is for after all

  4. added
    Area-RemotingCommunication layer between windows. Often for windowing behavior, quake mode, etc.
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    on Mar 26, 2021
  5. DHowett commented on Mar 26, 2021

    @DHowett
    Member

    Right, this is when you run wt -w 0 from an application hosted in the admin wt?

  6. miniksa commented on Mar 26, 2021

    @miniksa
    Contributor

    Weird, because I definitely can't repro this locally. Michael Niksa (@miniksa) Do you know if there's a way I could have David Jackman (@DJackman123) here collect the events emitted to a particular tracelogging GUID and send them to me? That is what all that logging is for after all

    Mike Griese (@zadjii-msft), you could ensure that the GUID you're thinking about is listed in src/ConsolePerf.wprp and then have David Jackman (@DJackman123) load that into Windows Performance Recorder with the Add Profiles... button in the bottom left, start the trace, repro the thing, then send you the recorded ETL file.

  7. DHowett commented on Mar 26, 2021

    @DHowett
    Member

    I've got a version of that file laying around that has Terminal GUIDs in it... Just a sec 😄

  8. miniksa commented on Mar 26, 2021

    @miniksa
    Contributor

    Here is a version of the WPR profile that has all the Terminal GUIDs.

    Dude. Put that in a PR and check that in.

  9. DJackman123 commented on Mar 26, 2021

    @DJackman123
    ContributorAuthor
  10. DHowett commented on Mar 26, 2021

    @DHowett
    Member

    huh. I don't love the implications that has on our activation stack.

    Hey, are you getting a different config file when you run from the Run dialog?

  11. DJackman123 commented on Mar 26, 2021

    @DJackman123
    ContributorAuthor

    What specifically do you mean by "different config file"?

  12. 19 remaining items

  13. zadjii-msft commented on Mar 16, 2022

    @zadjii-msft
    Member

    Huh. Nothing is throwing any errors in this trace. Nothing is obviously wrong (other than the second window being established as the monarch).

    • PID 56056 starts
      • Registers as the COM server for the Monarch class
      • Creates a monarch (its own process)
      • Starts up totally normally.
    • PID 121072 starts
      • Registers as the COM server for the Monarch class
      • Creates a monarch IN ITS OWN PROCESS (here, winrt::create_instance should have used the one that PID 56056 had already registered
      • Starts up normally as if it was the monarch
    • PID 120788 starts
      • Registers as the COM server for the Monarch class
      • Creates a monarch in PID 121072
      • Everything proceeds normally from here on out

    Because that second process effectively sniped the Monarch registration, it's performed a coup. Now the first window thinks it's the king but every other window doesn't, so the first window is totally isolated. I'm gonna need to reach out to the COM folks on this one. I did not think that it was possible for one process to snipe the CoRegisterClassObject of another process.

  14. zadjii-msft commented on Mar 17, 2022

    @zadjii-msft
    Member

    idly: maybe the alias is pointing at a different version of the Terminal? Or like, a different exe? So the first one opens the ....

    Nah that doesn't make sense. The Monarch is separated by "SKU", so Dev always talks to the same GUID, Preview always talks on a second GUID, and Release always on a third GUID, and those haven't changed. So if you did run Stable from the Start Menu, and wt.exe was pointing at Preview, then those windows would have wholly different settings. So that's not it.

    Presumably, when you're in this state, running the "Identify Window" command gives "Window: 1" for both the windows.
    image
    image

  15. zadjii-msft commented on Apr 28, 2022

    @zadjii-msft
    Member

    Filed MSFT:39320463 to track. From the mail thread, this doesn't seem like our fault, but we should still figure it out.

  16. added
    Tracking-ExternalThis bug isn't resolved, but it's following an external workitem.
    and removed
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    on Apr 28, 2022
  17. added
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    and removed
    Needs-Tag-FixDoesn't match tag requirements
    on Apr 28, 2022
  18. AltitudeApps commented on May 29, 2022

    @AltitudeApps

    Presumably, when you're in this state, running the "Identify Window" command gives "Window: 1" for both the windows.

    Confirmed. Actually, I have 3 windows open. Two are elevated, and one is not. ALL THREE indicate "Window: 1" in response to the Identify Window command from the command palette.

    I can confirm that the trick of running wt -w 0 nt again in the window that was launched (but shouldn't have launched) by a wt -w 0 nt command indeed does work, and it launches a new tab in this new window.

    So, I guess the workaround will be to immediately issue a wt -w 0 nt command after launching an elevated wt.exe instance, and then close the first window. Things seem to work as expected after that.

    Interestingly, I see that doing a wt -w 0 nt in EITHER of the elevated windows will result in a new tab appearing in the second window.

    edit: I just reproduced this on a second machine.

  19. zadjii-msft commented on Jul 17, 2023

    @zadjii-msft
    Member

    Okay we got some heavy investigative help on this on. From the internal bug notes:

    Flow is,

    1. User launches WindowsTerminal.exe as admin. Has Token A.
    2. WindowsTerminal.exe also launches an OOP COM server with Token A.
    3. Inside, OpenConsole.exe launches
    4. Inside, Powershell.exe launches, but .NET changes the token to add SeDebugPrivilege (for reasons). Token B!

    So now user has a normal looking terminal, but the tokens are already in a weird state between window process and shell process.

    User tries to open new tab with "wt.exe -w 0 nt" in terminal.

    1. wt.exe launches. With Token B (SeDebugPrivilege)!
    2. It then launches (the same) OOP COM. This should just fetch the existing instance from earlier, but,
    3. COM tries to find existing server
    4. Finds earlier instance
    5. Matches tokens Token A (first WindowsTerminal.exe instance) and Token B (new wt.exe instance).
    6. Tokens are different, so it makes a new OOP server. i.e. new window.

    now, if you change your default shell from powershell.exe -> cmd.exe, then the bug goes away!

    First. This doesn't repro on Desktop, but does on Centennial because there is an appmodel policy that changes COM's token matching function to be stricter for Centennial than Desktop, AppModelPolicy_ComTokenMatchingForAAAServers_UseNtCompareTokens.

    Second. Supposedly the stricter token matching policy is only used because there is no classInfo (IComClassInfo) retrieved for your COM class.

        wil::com_ptr_nothrow<IComClassInfo> classInfo;
        RETURN_IF_FAILED(TryGetClassInfoForActivation(*pActParams, &classInfo));

    because there's a bug in COM where they calculate the right thing for packages, but then clobber it by immediately recalculating that thing for Desktop. (I'm fuzzy on this part.)

    There's an upstream bug, MSFT:39730477 that this was now duped to.

    Major thanks to Jeff Whiteside (@jsidewhite) and Brian Alker (@brialmsft) for digging in on the COM side of things

  20. removed
    Needs-ReproWe can't figure out how to make this happen. Please help find a simplified repro.
    on Jul 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-RemotingCommunication layer between windows. Often for windowing behavior, quake mode, etc.Issue-BugIt either shouldn't be doing this or needs an investigation.Priority-2A description (P2)Product-TerminalThe new Windows Terminal.Tracking-ExternalThis bug isn't resolved, but it's following an external workitem.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions