43

I use shortcut Windows Key +R to run Windows Terminal [wt], but I cannot run it as Admin, which causes problems when I install something via choco.

  • To open it as Admin, I have to:
    Press Windows Key > Right-click Terminal > More > Run as Admin > > ENTER
  • Some solutions say to use the following, but it can only open powershell, not wt:
    Windows Key+X > A > > ENTER
  • While others say to use the following, but it also doesn't work:
    Windows Key+R > SHIFT+CTRL+ENTER

How do I open Windows Terminal as Admin via a command?

JW0914
  • 9,096
deuterium
  • 533

11 Answers11

27

A shell in Windows Terminal [wt] can be launched/relaunched as Admin in three ways:

  1. Pin Windows Terminal to the Taskbar: Shift + Right-click it → Run as Administrator

  2. Relaunch as Admin from within wt:
    # Cmd:
      Powershell -Command "Start-Process cmd -Verb RunAs"
    

    Powershell:

    Start-Process -FilePath "powershell" -Verb RunAs

    Pwsh:

    Start-Process -FilePath "pwsh" -Verb RunAs

    • These can be added as environment variables to PowerShell profiles [$Profile]:
      %UserProfile%\Documents\Windows Powershell\Microsoft.PowerShell_profile.ps1
      

      %UserProfile%\Documents\Windows Powershell\profile.ps1


  3. Add Relaunch-Admin function to profile, invoking Relaunch-Admin or alias psadmin:
    # Function to relaunch as Admin:
      function Relaunch-Admin { Start-Process -Verb RunAs (Get-Process -Id $PID).Path }
    

    Alias for the function:

    Set-Alias psadmin Relaunch-Admin

JW0914
  • 9,096
13

To start an executable as Admin from Run and Windows Menus, press CTRL+SHIFT+ENTER:

  • Run: WinKey+R
  • Windows Menus: Type the app's name > Right-click it > Select Open file location:
    1. Right-click on shortcut > Select Properties
    2. Shortcut tab > Advanced > Advanced Properties > Select Run as administrator
      (The app will always start as Admin from now on)

Additional options to run an app as Administrator

JW0914
  • 9,096
11

I found a nice workaround.
If you use Chocolatey to install "sudo" you can use sudo to activate any command as admin from inside The windows terminal. It will launch a separate window (either cmd or PowerShell) and provide a UAC prompt if enabled.

8

In older versions of Windows, Run... created tasks with administrative privileges, but in Windows 10, it no longer does; however, you can do it using Task Manager:

  • CTRL+SHIFT+ESC > File Menu > New task > Create task with administrative privileges
JW0914
  • 9,096
wasif
  • 9,176
8

You can create a shortcut to always run Windows Terminal as administrator using this powershell script:

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\Windows Terminal.lnk")
$Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminal_8wekyb3d8bbwe\wt.exe"
$Shortcut.Save()

$bytes = [System.IO.File]::ReadAllBytes("$Home\Desktop\Windows Terminal.lnk") $bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON [System.IO.File]::WriteAllBytes("$Home\Desktop\Windows Terminal.lnk", $bytes)

It basically creates a Windows Terminal.lnk file on your desktop, when you run it runs Windows Terminal as an administrator.

3

The approach closest, in spirit, to your original request would be to place Windows Terminal as a taskbar shortcut and use Ctrl+Shift+Win+#. The # pressed should be the actual number key on the number row that corresponds to taskbar position, 1 being the leftmost position and 0 being rightmost. This will launch a new instance of the application as admin, even if an existing instance is already open.

The only issue is I'm not sure if this works prior to Windows 10.

Curtis
  • 31
2

I know this is not directly related to the question, but I consider this a big improvement for people like me which needs to always run as an Administrator (please do not do it just for the sake of it, higher permissions can represent a security risk).

I always need to run PowerShell as Administrator and I only want to use Windows Terminal, which given it's restrictions cannot be configured to run always as Administrator.

I hated the need to use shortcuts and other hacks I found being suggested online, so I think I found a better solution but you have to pay the cost of a 1/2 seconds at startup.

  1. Locate your user profile (A profile is a Windows PowerShell ISE script that runs automatically when you start a new session) using _ $PROFILE
  2. Edit profile with any preferred editor _ code $PROFILE
  3. Adde the following code to the profile file and save it
if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
    $host.ui.rawui.windowtitle="Bootstrapper"
    Start-Process -Verb RunAs wt
} else {
    $Processes = Get-Process | Where-Object {$_.mainWindowTitle -eq 'Bootstrapper' -and $_.name -eq 'WindowsTerminal'}
    if($Processes.count -gt 0)
    {
        Stop-Process -Id $Processes[0].id
    }
}

What the script do? You can pin Windows Terminal icon to your application bar and when you click there WT will start as non elevated user, but the profile will understand if this is the case. When you are not running as Administrator it will change the name of the window and start a new WT as administrator. The new instance will also execute the profile file and if the instance is running as Administrator, it will look for the WT named Bootstrapper and kill it. This process takes between one and two seconds, I prefer this way other than right clicking on the icon.

Norcino
  • 121
  • 3
2

In Windows 10 21H1, I have done the following:

  1. Go to C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.9.1942.0_x64__8wekyb3d8bbwe
  • note that you might need to change the Owner for the WindowsApps folder from the folder Properties->Security->Advanced from SYSTEM to Administrators.
  • also note that the name of the WindowsTerminal folder might change, depending on the version you're using.
  1. Find wt.exe and from it's properties, in Compatibility, tick the box where it says "Run as administrator". You might have to "Change settings for all users."
  2. Save.
  3. Create a shortcut of wt.exe & copy it in your C:\Windows folder

This is the only thing that worked for me AND you just need to Windows+R->wt->enter to open it as admin. No Shift key required.

Also note that applying these settings to "C:\Users\$env:username\AppData\Local\Microsoft\WindowsApps\wt.exe" won't work.

It still opens as non-admin, from Run or Start.

There's one thing that may or may not bug you about this. When you update Windows Terminal, the permissions of the wt.exe might break/revert to default, which means you'll need to set them back as they were.

StayOnTarget
  • 1,494
0

The easiest way I did it is to:

  1. Go to the folder that it is installed & copy all files and folder in that directory
  2. Create a folder on C:\ or anywhere you have Admin rights and name it whatever you'd like.
  3. Paste the contents
  4. Create a shortcut to run as Admin
  5. Pin To Taskbar

This way worked best for me because some reason I had permissions issues to it in the Program Files directory.

0

Add a shortcut to your taskbar then Ctrl+Shift click will open as Administrator

Jethro C
  • 159
  • 1
  • 3
0

It's much more simple:

  1. Open Apps > Terminal.
  2. Above in the window of the terminal menu go to v (dropdown) > Settings.
  3. A new window appears. On the left side of it go to Profile > Defaults
  4. On the right plane of Defaults go down to Run this Profile as Administrator and activate it by clicking the switch.

Next time you start Windows Terminal it'll start in admin mode.

More exact answer to the question is: if you really like to open it with Win + R > wt then you have to change the properties of the wt.exe executable so that it runs as administrator in C:\Program Files\WindowsApps\Microsoft.WindowsTerminal_1.16.10261.0_x64__<your 13 App letter and numbers>\. The _1.16.10261.0 part depends on the installed version.

Destroy666
  • 12,350
HL1234
  • 1