41

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
  • 7,052
  • 7
  • 27
  • 48
deuterium
  • 513
  • 1
  • 4
  • 6
  • Usually, all you have to do is enter your command in the Run box, press Shift and click OK with the Shift key down. –  Jun 12 '20 at 06:59
  • 3
    i tried so,it does open the programme,but not as admin as i want.@Didier – deuterium Jun 12 '20 at 12:39
  • There's no reason for it not to work: Ctrl-Enter is the keyboard equivalent of clicking on the OK button, and Shift gets you elevated rights. It sure works on my own Windows 10 when I'm logged on as regular user with admin rights. Are you sure you have local admin rights on this account? EDIT: this said, I haven't upgraded to 2004 yet. –  Jun 12 '20 at 16:29
  • @Didier yes,i'm using win 10 1909 as so.but it just not work as expected.seems i need to chect if it works on other computers. ps:my system is pre-installed with a laptop,will it influences? – deuterium Jun 20 '20 at 02:19
  • 1
    When you attempt to run Windows Key+R > SHIFT+CTRL+ENTER, presumably you type `wt` in the run box before pressing ctrl + shift + enter, right? I just tried it on windows 10 21h1 and that works for me to launch terminal as admin (and presumably anything I type in the run box as admin if I wanted...thanks for that tip!) – Brad P. Jul 21 '21 at 19:15
  • @BradP. instructions worked for me – Ricardo Sanchez Mar 22 '23 at 14:10

11 Answers11

26

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
  • 7,052
  • 7
  • 27
  • 48
  • Seems the 2 way need to change system profile,i found some infomation about it,but none of them talked about which file i need to edit. – deuterium Jun 14 '20 at 09:10
  • also,i do not understand the 3 way,can u give it a more spcific discribtion,for I think it may be the final solution,thank you for your knolodge. – deuterium Jun 14 '20 at 09:13
  • I don't know much about OS,or something like how a file is start,so these information may not enough fr me to realize. – deuterium Jun 14 '20 at 09:15
  • @deuterium For #2, issue any of those from Powershell, which is also the default shell of `wt` unless customized by the user, and it will launch an Admin terminal. For #3, you'd copy/paste that into `%UserProfile%\Documents\Windows Powershell\Microsoft.PowerShell_profile.ps1`, as well as `%UserProfile%\Documents\Windows Powershell\profile.ps1` if it exists, then reload the Powershell profile via `& $profile` – JW0914 Jun 14 '20 at 11:51
  • 2
    When I use this, it opens up a new Powershell instead of Windows Terminal. How to set it up so that I can run Powershell as admin within WT? – TYeung Jan 13 '21 at 08:02
  • @LearningMathematics That I do not know - what you may want to do is open an issue on the Windows Terminal [GitHub](https://github.com/Microsoft/Terminal) asking the same, as you'll likely get an answer faster from there. – JW0914 Jan 13 '21 at 13:26
  • @TYeung Executing that command/alias does now open it within WT. While I don't have links to Microsoft Docs for this, due to the way Windows Terminal is coded, launching an admin terminal within WT will also always open that admin terminal in a new WT instance, as it's not recommend to open an admin terminal within a WT instance containing non-admin terminals since it allows potential privilege escalation in the non-admin terminal. – JW0914 Jul 26 '23 at 14:07
11

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
  • 7,052
  • 7
  • 27
  • 48
user2380383
  • 327
  • 1
  • 10
  • that is the problem.CTRL+SHIFT+ENTER does not work at all from Run.that is the perfect way i perfer,cause pther way rely on mouse move to some special place,which means not "fluent" for me.same happend so when i choose start menu(it needs some time to load) – deuterium Jun 12 '20 at 12:44
  • i tried the second way,srom bad to worse,when i use start menu,system tells me he "has no access to the file" (not very sure,i'm not using a english system).luckily it is fixed after reinstall. – deuterium Jun 12 '20 at 12:47
  • 1
    Regarding the link, the issue is `wt` doesn't work like other programs and appears to not have a way baked in to launch it as Admin outside of context menus. To determine for sure, it's GitHub page, man page, and issues page would need to be referenced, as Trying to launch `wt` as Admin through normal means doesn't work. _(please also use the correct markdown for weblinks =] )_ – JW0914 Jun 13 '20 at 01:39
  • yes,i'm using win 10 1909,you need not to assum if you noticed the tag "windows-10". – deuterium Jun 14 '20 at 08:56
  • @JW0914 sorry for bad grammer of md. but it seems a general problem that CTRL+SHIFT+ENTER not work,notice a link i refered reports the problem happened on cmd.exe.\nit'strange that cmd do not work so,but mspaint do,and later when i try,cmd did too. – deuterium Jun 14 '20 at 08:59
  • 2
    @deuterium I would recommend opening an issue on Windows Terminal's GitHub page, as there should be a single command that allows `wt` to open an Admin shell via cli, and `wt` doesn't offer anything beyond `new-tab`, `split-pane`, and `focus-tab` _(the markdown request was for user23803838)_ – JW0914 Jun 14 '20 at 11:36
  • 1
    CTRL+SHIFT+ENTER does work with 'PowerToys Run' utility to launch WT as admin. Interestingly CTRL+SHIFT+ENTER click also works on taskbar icon, no need to us a context menu. – Seamus Oct 16 '20 at 17:01
10

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.

joshinator414
  • 116
  • 1
  • 2
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.

  • 1
    This is pure gold! Now if only you could tell me how to pin the created shortcut to my taskbar, and have it so that clicking on that tile *doesn't create another ungrouped tile* after all others...well then you, sir, would become my god! LOL :P – Kenny83 Jan 04 '21 at 11:02
  • 3
    Awesome, thank you. For those looking for the icon file: https://raw.githubusercontent.com/microsoft/terminal/main/res/terminal.ico – Oneiros Mar 04 '21 at 15:06
  • @Kenny83 just drag'n'drop it on your taskbar. – Serhiy Apr 03 '21 at 12:43
  • This is dope! I had to update the path to `$Shortcut.TargetPath = "$env:LOCALAPPDATA\Microsoft\WindowsApps\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\wt.exe"` though – Alexandre Daubricourt Sep 09 '21 at 07:46
6

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
  • 7,052
  • 7
  • 27
  • 48
Wasif
  • 7,984
  • 2
  • 19
  • 32
  • My method is way quicker, I dare say... :-) –  Jun 12 '20 at 09:37
  • i'm searching for a way as fast as possible,which makes me have a sense of "fluent" i now opens startmenu and click,which seems even more faster then the method you offer.sorry~ – deuterium Jun 12 '20 at 12:50
  • 1
    @Didier u r way does not work! Notice deuterium's comment – Wasif Jun 12 '20 at 15:11
  • 1
    @WasifHasan Run... still offers this functionality, Windows 10 just removed the redundancy of the checkbox; in Run... press `SHIFT`+`CTRL`+`ENTER`/`OK` – JW0914 Jun 14 '20 at 11:44
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 Onwer for the WindowsApps folder from the folder Properties->Security->Advanced from SYSTEM to Adminstrators.
  • 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

Thsi 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.

2

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
  • 21
  • 2
1

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
  • 111
  • 3
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

Ben Collins
  • 129
  • 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
  • 5,299
  • 7
  • 16
  • 35
HL1234
  • 1
  • 1