Terminal: Launching wt.exe as admin fails

Created on 10 Oct 2019  路  9Comments  路  Source: microsoft/terminal

Environment

Windows build number: 18363.418
Windows Terminal version (if applicable): 0.5.2762.0

Steps to reproduce

  • Open Start Menu
  • Type wt to get the shortcut to WinTerm
  • Click Run as Administrator

Expected behavior

WinTerm should run as administrator

Actual behavior

There is an error and a box appears with:

[Window Title]
C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe

[Content]
C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe

The file cannot be accessed by the system.


[OK]

Comment: Running as admin from the Windows Terminal (Preview) shrortcut icon in the start menu works fine.

Needs-Tag-Fix Resolution-External

All 9 comments

This is an OS bug that we're pursuing internally. Thanks for reporting!

@DHowett-MSFT is there any bug tracking system where we can watch/subscribe for updates on this issue?

@Serhiy-Shekhovtsov just this one. Sorry!

Sorry to bug, but I just wanted to check, could we not provide a secondary launcher exe that can be launched in Admin and launches wt.exe for us? The most simple version of this seems to work with Admin just fine.

This should probably only really be considered if the external issue is going to take a long time to resolve, but it's a decent workaround in the meantime. (And even if Windows Terminal doesn't provide it, others might want to know you can do it.)

Unfortunately, unless we ship it as a sidecar (like, an executable that you have to download and install separately), it's going to be subject to the same issues as wt.exe itself. Things that live in appx/msix packages are simply _troublesome_ in this regard.

I see, thanks!

in the interim, use a 3rd party launcher, e.g. nircmd

nircmd.exe elevate "shell:appsFolder\Microsoft.WindowsTerminal_8wekyb3d8bbwe!App"

confirm metro app path via powershell:

Get-appxpackage *WindowsTerminal*

This works without additional programs

so you can make a shortcut

Source of elevate see: https://stackoverflow.com/a/12264592/1016343

elevate_windows_terminal.bat

::::::::::::::::::::::::::::::::::::::::::::
:: Elevate.cmd - Version 4
:: Automatically check & get admin rights
:: see "https://stackoverflow.com/a/12264592/1016343" for description
::::::::::::::::::::::::::::::::::::::::::::
 @echo off
 CLS
 ECHO.
 ECHO =============================
 ECHO Running Admin shell
 ECHO =============================

:init
 setlocal DisableDelayedExpansion
 set cmdInvoke=1
 set winSysFolder=System32
 set "batchPath=%~0"
 for %%k in (%0) do set batchName=%%~nk
 set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
 setlocal EnableDelayedExpansion

:checkPrivileges
  NET FILE 1>NUL 2>NUL
  if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
  if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
  ECHO.
  ECHO **************************************
  ECHO Invoking UAC for Privilege Escalation
  ECHO **************************************

  ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
  ECHO args = "ELEV " >> "%vbsGetPrivileges%"
  ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
  ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
  ECHO Next >> "%vbsGetPrivileges%"

  if '%cmdInvoke%'=='1' goto InvokeCmd 

  ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
  goto ExecElevation

:InvokeCmd
  ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
  ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"

:ExecElevation
 "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
 exit /B

:gotPrivileges
 setlocal & cd /d %~dp0
 if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

 ::::::::::::::::::::::::::::
 ::START
 ::::::::::::::::::::::::::::
 REM Run shell as admin (example) - put here code as you like
 start D:\bat\windows_terminal\windows_terminal.bat
 exit

plus

windows_terminal.bat

start C:\Users\<username>\AppData\Local\Microsoft\WindowsApps\wt.exe
exit

Change username

If anyone is still looking for a simpler work-around, here is one.

You can create a shortcut with location pointing to the following command.

  1. Right click -> New -> Shortcut
  2. Type in C:\Windows\System32\cmd.exe /c start /b %USERPROFILE%\AppData\Local\Microsoft\WindowsApps\wt.exe for the location
  3. Give whatever name you want to give, finish.
  4. Right click on the newly created shortcut -> Properties -> Advanced -> Run as administrator

This shortcut will now open WT in admin mode. You can use this shortcut file from non-privileged cmd/wsl also to open a new Terminal window in admin mode.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghvanderweg picture ghvanderweg  路  3Comments

dev-logan picture dev-logan  路  3Comments

Wid-Mimosa picture Wid-Mimosa  路  3Comments

mdtauk picture mdtauk  路  3Comments

TayYuanGeng picture TayYuanGeng  路  3Comments