Create a tab in Windows Terminal that is run as a different user?

So I can run...

runas /user:PNG\SomeSvc "cmd /c ^"powershell.exe^""

And get a powershell prompt that's run by a different user.

But if I'm using Windows Terminal and I want to run it as a different user, how would I do that? I'm sure it probably has something to do with the json configuration file.

Also, is there anything I would need to use for authentication if I store the file in a secure string or "Windows Credential Manager" via the New-StoredCredential commandlet?


Solution 1:

Your question title and the question body don't feel quite aligned to me. The question title asks:

Create a tab in Windows Terminal that is run as a different user?

But your question body (and the existing PowerShell example) seem to be slightly different:

But if I'm using Windows Terminal and I want to run it as a different user, how would I do that?

Since I can't quite be sure if you want one tab in Windows Terminal to be elevated, or if you just want to launch Windows Terminal as elevated, I'll answer both:

Elevating a single tab

You can't UAC-elevate your user for a single tab. See Windows Terminal Github Issue #632 and #691 for more info. Warning, #632 is a very long read.

You can probably get around this with some combination of PowerShell remoting and/or OpenSSH. I did a few quick tests since I have Windows OpenSSH server already enabled:

  • Enabled Windows Administrator (which I promptly disabled again after trying this)
  • Set a password on the Administrator account
  • ssh'd in to localhost as my regular user
  • Start PowerShell or PowerShell core (I already have it set as my default OpenSSH shell)
  • $cred = New-Object -type System.Management.Automation.PSCredential "Administrator", (Read-host -AsSecureString)
  • Enter-PSSession -ComputerName localhost -Credential $cred
  • whoami results in computername\Administrator

Note Enter-PSSession -ComputerName localhost won't work directly from a Windows Terminal tab since it (chicken-and-the-egg) requires that it be elevated ...

Elevating Windows Terminal

However, it is quite easy to start a new Windows Terminal process that is elevated.

My usually command for doing this is, from PowerShell:

Start-Process wt -Verb RunAs

You can also "Run as Administrator" from the Start Menu or pinned Taskbar entry. This will, of course, bring up the UAC prompt.

I haven't tried this, but if you wanted to run wt.exe with the Administrator credentials, you would at least need to:

  • Enable the Administrator account with a password
  • Log in to Windows with that account
  • Install Windows Terminal from the Store

Otherwise, that user won't have it installed in their account anyway.

Or you can circumvent that by installing the non-Store version of Windows Terminal. Note, however, that Microsoft considers this an "unsupported" configuration.