16

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?

4
  • Usually, all you have to do is enter your command in the Run box, press Shift and click OK with the Shift key down. – user1019780 Jun 12 '20 at 6: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. – user1019780 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 2:19
9

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 to the following user Powershell profiles [$Profile] as environment variables:
      • %UserProfile%\Documents\Windows Powershell\profile.ps1
      • %UserProfile%\Documents\Windows Powershell\Microsoft.PowerShell_profile.ps1
  3. Add Relaunch-Admin function to the Powershell profiles above and invoke by 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
    
6
  • 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 9: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 9: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 9: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
  • 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? – Learning Mathematics Jan 13 at 8:02
5

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
4
  • My method is way quicker, I dare say... :-) – user1019780 Jun 12 '20 at 9: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
  • @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
3

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

7
  • 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 1: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 8:56
  • 1
    @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
3

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
  • 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 4 at 11:02
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.