microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.66k stars 8.33k forks source link

Add "Run As Administrator" menu option to Start Menu and Taskbar #4459

Open wsmelton opened 4 years ago

wsmelton commented 4 years ago

Description of the new feature/enhancement

Ability, primarily in Windows, to easily open the terminal app in an elevated session. Either via the Start Menu icon, as the PowerShell app does it, or via the taskbar icon.

Example for Start Menu: image

Example for Taskbar icon: image

DHowett-MSFT commented 4 years ago

Your start menu screenshot is a screenshot of our issue template 😄

abvgdeyoj commented 4 years ago

Afaik this is already possible. (Russian locale - don't panic) 1 2 3

wsmelton commented 4 years ago

My point is to make it more accessible, not that it is not possible.

Having to right click twice from the taskbar icon when it is a command need is inefficient.

abvgdeyoj commented 4 years ago

Now, Windows Terminal is not:

  1. An app you have to launch often because of TDI
  2. An app you can't make a "Run as Administrator" shortcut for. (Not directly, but "C:\Windows\system32\cmd.exe /c start /b wt" works)
  3. An app for which the aforementioned shortcut could not be placed in the "Startup" folder, Desktop, Taskbar, key binding, etc...

I don't feel it's that much needed to duplicate an existing feature in such a unsystematic and aesthetically frustrating manner.

I know that we are talking about a product intended mainly for Windows, in which POLP is often neglected, but I do want to bring up that running something by default with elevated privileges is considered to be a bad practice.

DHowett-MSFT commented 4 years ago

This'll also require us to look at the newWindow key binding and the jump list (#576). I was going to close this and link it to #1032, but it's distinct and tractable enough to stand on its own. Thanks.

jbpaux commented 4 years ago

Yes please ! Implement it like in pwsh with JumpList tasks : https://github.com/PowerShell/PowerShell/tree/db370dcc794e2f7b3c93e00b4538f1485d937f13/src/Microsoft.PowerShell.ConsoleHost/WindowsTaskbarJumpList

erenken commented 4 years ago

I would actually love to see the Run As Administrator also in the drop-down in the Terminal application where you select which terminal you want. This would make quick access and then I would only do it when I really needed to. I know it would need to start up a new process, but have that process start in the terminal mode I selected and elevated would be awesome.

cstueckrath commented 4 years ago

I see more issues with the whole app concept. I am not a local administrator on my machine, so I elevate with another user. The problem is, that the application is unknown in the context of this user, and because you cannot run the Store as admin or another user, you have to log with every single user you need to run Terminal as and install/update from store...

wsmelton commented 4 years ago

@cstueckrath that would be how apps work from the Windows Store, everyone of them work in that manner (few exceptions, but not many).

Option would be to just grab the msix file from the release page of this repository and try to install it under the context of just that user.

cstueckrath commented 4 years ago

@wsmelton I know, and I don't mind running calculator or paint as "Apps", but for management tools? They should be available and updateable system wide. Maybe I don't get the concept of all this, but neither of those Store-tools will be usable in my environment - and we don't even talk about those people using Win10 LTSB...

swinster commented 4 years ago

FWIW, I have literally just installed Terminal, it took me around 10-15 seconds to ask myself "how to I run a terminal as an administrator". I clicked feedback, then search open issues for "administrator" and came here....

abvgdeyoj commented 4 years ago

@cstueckrath The entire "Apps" concept still has a long way to ever get to the point where Windows is a modular system consisting of "Apps", but seeing the developers attitude under Nadella, chances are that Windows will crack open its sources like NetScape back in the days, and Azure (or Outlook, or Xbox Game Pass) will be his main business long before that might happen. As for the LTSB, Microsoft Store is not needed for .appx or .msix to be installed

dpokluda commented 4 years ago

I would like to add Windows Terminal to Start menu and Taskbar so that when I click it, it will start elevated. How do I do that (without right-clicking)?

igor-teresco commented 4 years ago

Create a shortcut to "C:\Windows\system32\cmd.exe /c start /b wt", set it to be Run As administrator from properties.

garyng2000 commented 4 years ago

yes, but instead of menu option, can't we have the simple 'sudo bash' equivalent ? we are talking about console/command line here :-)

zadjii-msft commented 4 years ago

@garyng2000 Unfortunately, it's not that simple. You may be interested in https://github.com/microsoft/terminal/issues/1032#issuecomment-496308808

garyng2000 commented 4 years ago

I don't quite understand the #1032 issue, I assume you meant security.

What would be the difference between 'sudo bash' vs 'right click' then run as Admin on the start menu ?

I don't really need to have the 'current terminal' session to be the parent of the 'elevated shell', but just give me a completely unrelated shell is fine. The usage scenario is just 'I am already in the directory I am in and need elevation for certain tasks'. VS Code can do this too when I try to save files under '\Windows' so why the 'terminal' app cannot ?

Though not a big issue as I already have the habit of just having a few 'admin' shell opened via the 'right click' route.

zadjii-msft commented 4 years ago

For sudo bash, bash is fundamentally still running in an unelevated window, so other unelevated applications can send keystrokes to bash by sending keystrokes to the unelevated terminal window.

When you right-click "run as admin" launch a process, it spawns a new terminal window, and that window is elevated, so it's protected from input being injected by other applications.

This is the fundamental reason there isn't a builtin in-console elevation exe like sudo on Windows.

I believe that Start-Process -Verb RunAs cmd (in powershell) will actually create a new elevated console window to run the elevated process, which sounds a lot like what you're looking for.

garyng2000 commented 4 years ago

yes, but that is a lot of typing vs 'sudo bash'(and I have to include the working directory as well which becomes even longer) :-)

I would say 90% of the usage of 'sudo bash' is what I am doing(well may be there are some exotic way in the linux world utilizing what you mentioned but I have no experience of that personally).

3col commented 4 years ago

I've been using these context menu shortcuts: (https://www.tenforums.com/tutorials/60132-open-bash-window-here-administrator-add-windows-10-a.html)](https://www.tenforums.com/tutorials/60132-open-bash-window-here-administrator-add-windows-10-a.html) to be able to quick and easy open "Open command/bash window here as administrator".

Did few modifications, but some less cryptic way would be nice too:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenTerminalHereAsAdmin]
@="Open Terminal here as administrator"
"Extended"=-

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenTerminalHereAsAdmin\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd -Verb RunAs -ArgumentList '/c start wt -p cmd -d \"\"%V\\.\"\"'\""

[HKEY_CLASSES_ROOT\Directory\shell\OpenTerminalHereAsAdmin]
@="Open Terminal here as administrator"
"Extended"=-

[HKEY_CLASSES_ROOT\Directory\shell\OpenTerminalHereAsAdmin\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd -Verb RunAs -ArgumentList '/c start wt -p cmd -d \"\"%V\\.\"\"'\""

[HKEY_CLASSES_ROOT\Drive\shell\OpenTerminalHereAsAdmin]
@="Open Terminal here as administrator"
"Extended"=-

[HKEY_CLASSES_ROOT\Drive\shell\OpenTerminalHereAsAdmin\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd -Verb RunAs -ArgumentList '/c start wt -p cmd -d \"\"%V\\.\"\"'\""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenTerminalHereAsAdmin]
@="Open Terminal here as administrator"
"Extended"=-

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenTerminalHereAsAdmin\command]
@="PowerShell -windowstyle hidden -Command \"Start-Process cmd -Verb RunAs -ArgumentList '/c start wt -p cmd -d \"\"%V\\.\"\"'\""
dflor003 commented 4 years ago

I spent about 5 minutes right clicking on the pinned icon I had for the terminal in my taskbar trying to figure out why I couldn't see "Properties" in there and use that to set it to always run as admin...

Every other application I've ever used on windows lets me set it to run as an administrator automatically using that.

Eventually I figured it was because it was a windows store app which for some reason gives it a completely different menu than everything else, but that really clashes with my expectations as a user.

Putting this automatic "Run as Administrator" feature would at least let us get parity with the functionality we as users are used to.

garyng2000 commented 4 years ago

you just need to do it differently for this. right click then right click on the 'app title' again and you see the menu. weird but that is how it works. true store app like the 'store' itself just can't do this 'run as admin'

dflor003 commented 4 years ago

you just need to do it differently for this. right click then right click on the 'app title' again and you see the menu. weird but that is how it works. true store app like the 'store' itself just can't do this 'run as admin'

I see the menu, but there's no "Properties" in there that I can set it to always run as administrator.

garyng2000 commented 4 years ago

ah, that is not possible AFAIK for security reason. The WindowsApp is locked down, not even admin can access it so all these tricks of changing property would not work.

Elepover commented 4 years ago

Just found this blog post.

Credit: Daniel-Fisher-(lennybacon)

This is a dirty approach (but man ANYWAY IT WORKS): patching lnk file to force "tick" the "Run as Administrator" checkbox.

$linkFilePath = "C:\Users\$([Environment]::UserName)\Desktop\WindowsTerminal.lnk"
$bytes = [System.IO.File]::ReadAllBytes($linkFilePath)
$bytes[0x15] = $bytes[0x15] -bor 0x20 #set byte 21 (0x15) bit 6 (0x20) ON
[System.IO.File]::WriteAllBytes($linkFilePath, $bytes)

Though this is not considered as a clean & elegant approach, it still works perfectly.

schuelermine commented 4 years ago

About this being a duplicate of existing features: No. In the task bar, for instance, you can't select "Run as Administrator". This is btw also what PowerShell does...

Melvin-Abraham commented 4 years ago

Having an option like "Run as admin" within the context menu for a tab/pane would also be more accessible and let users give a particular tab/pane elevated privileges on demand.

schuelermine commented 4 years ago

I think having a quick action available directly when right-clicking the taskbar icon is easier than right-clicking once, then right-clicking again on the executable.

spixy commented 4 years ago

Having admin privileges for whole terminal seems wrong to me. Right click submenu would be nice though:

image

or add this option in settings.json:

{
   ...
   "commandline": "cmd.exe",
   "elevated": true
}
wsmelton commented 4 years ago

The restriction I see in doing that @spixy (at least from my limited understanding and dealing with other apps in Windows) is Windows won't allow you to spawn a child process as elevated while your are in a non-elevated process (wsl). I hit this at times with various applications now.

abvgdeyoj commented 4 years ago

Without major changes to how WT works, one way would be to implement it the same as we have in many SysInternals, and that is to add an option to restart the entire process elevated. png It 's not the best solution, but it works for me and should solve most of comments regarding "Run as Admin" being hard to find.

spixy commented 4 years ago

@wsmelton interesting, but ConEmu can do it somehow 🤔 image image (orange = elevated process)

DHowett commented 4 years ago

These past few comments are better suited for #632, where we're having an ongoing discussion about why it's okay for third party developers to do this but not us (right now). Please direct further discussion that is not about adding "Run as Administrator" to the Start Menu and Taskbar to #632.

tssva commented 4 years ago

Until this gets implemented those that are double right clicking to run as administrator may instead want to perform a shift-right-click which will bring you directly to a menu with the "Run as administrator" option.

jbpaux commented 4 years ago

Until this gets implemented those that are double right clicking to run as administrator may instead want to perform a shift-right-click which will bring you directly to a menu with the "Run as administrator" option.

Or just ctrl shit left click to open directly as admin ;)

ghost commented 4 years ago

For sudo bash, bash is fundamentally still running in an unelevated window, so other unelevated applications can send keystrokes to bash by sending keystrokes to the unelevated terminal window.

When you right-click "run as admin" launch a process, it spawns a new terminal window, and that window is elevated, so it's protected from input being injected by other applications.

This is the fundamental reason there isn't a builtin in-console elevation exe like sudo on Windows.

I believe that Start-Process -Verb RunAs cmd (in powershell) will actually create a new elevated console window to run the elevated process, which sounds a lot like what you're looking for.

@zadjii-msft why not a command like sudo bash which open the whole windows terminal in a new window with elevated mode and closes the previous terminal window, that way the un-elevated window will be closed and the new window will be in the elevated mode . Let's say i open the terminal using wt -d . so that it opens in the current directory, but wt opens in non-elevated mode. So if there was an option to enter elevated mode in the current directory, that would be very useful.

webluke commented 3 years ago

Run as Administrator should have been part of the first release. Now that it hasn't I hope they get it right and make it as easy as right-clicking on a profile and selecting "Run as Administrator". It must be a profile > list option in the json config.

Something like this.. "administrator": true

zadjii-msft commented 3 years ago

@webluke Boy, would you be interested in #8455, #8514, #5000 and all its linked threads.

zadjii-msft commented 2 years ago

FWIW This will probably need #12191 to add --elevate to the wt commandline args, and then it should be fairly trivial to add a jumplist entry that points at wt --elevate.

dmitrykok commented 1 week ago

As I understand, we do have:

Right click on terminal icon on taskbar (1) ⇒ right click on terminal menu terminal itself icon (2) ⇒ we have "Run As Administrator" option:

Image

Nice to have:

Right click on terminal icon on taskbar (1) ⇒ right click on terminal menu, any profile icon (2) ⇒ we have only "Open" option, but want to have also "Run As Administrator" option:

Image

I want to implement it.


And actually we do have option to run as admin any profile from profiles menu, open profiles "drop down" and right click on any profile:

Image