Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "open Windows terminal here" into right-click context menu #1060

Closed
yanglr opened this issue May 30, 2019 · 235 comments · Fixed by #6100
Closed

Add "open Windows terminal here" into right-click context menu #1060

yanglr opened this issue May 30, 2019 · 235 comments · Fixed by #6100
Assignees
Labels
Area-User Interface Help Wanted Issue-Feature Product-Terminal Resolution-Fix-Committed
Milestone

Comments

@yanglr
Copy link

@yanglr yanglr commented May 30, 2019

Add "open Windows terminal here" to right-click context menu?

We know that, for windows 7, by default when we click "shift + right click with mouse" when we enter into a folder without selecting anything, we can see the option "open command window here".

image

While for windows 10, by default when we click "shift + right click with mouse", we can see the option "open powershell window here".

So for Windows 10 (version later than 1903), how can we make the following three options available in right-click context menu?

  • open command window here
  • open powershell window here
  • open Windows terminal here

Looking forward to your reply, thanks a lot~

@yanglr yanglr added the Issue-Feature label May 30, 2019
@msftbot msftbot bot added Needs-Triage Needs-Tag-Fix labels May 30, 2019
@yanglr yanglr changed the title Is there a method to add "open Windows terminal here" to right-click context menu? Is there a method to add "open Windows terminal here" into right-click context menu? May 30, 2019
@SJang1
Copy link

@SJang1 SJang1 commented May 30, 2019

If adding it, I think it should have one more select option in open Windows terminal here to select actually what shell to open as submenu of context menu (or like that) with the 'name' wrotted in profiles of terminal, like

  • Powershell
  • CMD
  • Ubuntu

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented May 30, 2019

I think this is a good feature request, and something that we'd definitely accept help from the community on.

My gut says that it'd be related to work for #689, but I don't know enough about Win32 to be sure.

@zadjii-msft zadjii-msft added Area-User Interface Help Wanted Product-Terminal labels May 30, 2019
@msftbot msftbot bot removed the Needs-Tag-Fix label May 30, 2019
@zadjii-msft zadjii-msft added this to Spec Needed ❓ in Specification Tracker via automation May 30, 2019
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone May 30, 2019
@miniksa
Copy link
Member

@miniksa miniksa commented May 30, 2019

This is probably something like this: https://www.codeproject.com/Articles/441/The-Complete-Idiot-s-Guide-to-Writing-Shell-Extens

But hopefully without re-introducing ATL into our codebase...

@factormystic
Copy link

@factormystic factormystic commented May 30, 2019

It's way, way easier than that to add a single command to a folder context menu. It's just a simple registry key.

For example (and then you can also add an icon, etc)

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\Open Thing Here\command]
@="C:\\thing.exe \"%1\""

@ChrisGuzak
Copy link
Member

@ChrisGuzak ChrisGuzak commented May 30, 2019

for pacakged apps this is declared in the manifest. see this: https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-uap-filetypeassociation. I don't think this supports folders but start looking here.

@DHowett-MSFT
Copy link
Contributor

@DHowett-MSFT DHowett-MSFT commented May 30, 2019

Likely duplicate of #561, but we'll track it here.

@DHowett-MSFT DHowett-MSFT changed the title Is there a method to add "open Windows terminal here" into right-click context menu? Add "open Windows terminal here" into right-click context menu May 30, 2019
@DHowett-MSFT DHowett-MSFT removed the Needs-Triage label May 30, 2019
@yanglr
Copy link
Author

@yanglr yanglr commented May 31, 2019

@miniksa @zadjii-msft @DHowett-MSFT @factormystic @ChrisGuzak

I solved the issue now, it could be closed. Thanks a lot to all who involved into this discussion.

Step 0:

Test if two constants below works well which will be used in following other steps.

echo %USERPROFILE%

echo %LOCALAPPDATA%

If everything works well here, then these two constants can be used directly in other below steps.

Or please perform following replacements in below steps:

%USERPROFILE% → C:\Users\[userName]
%LOCALAPPDATA% → C:\Users\[userName]\AppData\Local

Here [userName] represents your user name,for instance, mine is Bruce.

Step 1:
Run below stuff in CMD:

mkdir "%USERPROFILE%\AppData\Local\terminal"

image

Step 2:
Copy the windows terminal icon to the folder %USERPROFILE%\AppData\Local\terminal, the icon can be obtained in https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal/icons whose file name is wt_32.ico.

Step 3:
Save follwing content as wt.reg, then run as administrator.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt_32.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"

To be noted, if the exe obtained after building code by yourself is wtd.exe, you need to change the above wt.exe to wtd.exe in the above registry.

Step 4:
Test
image

@SJang1
Copy link

@SJang1 SJang1 commented May 31, 2019

That didn't work to me (can't access to it error), and for me it was wtd.exe(didn't even work).
And I think this could be the Terminal Feature.

@yanglr
Copy link
Author

@yanglr yanglr commented May 31, 2019

@SJang1
I guess you used the version you bulit yourself, so need to use wtd.exe. For incoming official version to enter into Windows Store, wt.exe is the correct option here. For now, you can obtain preview version here (.7z file under https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal), then use wt.exe after installed. I adopted this method.

@SJang1
Copy link

@SJang1 SJang1 commented May 31, 2019

@yanglr I have used wtd.exe, and didn't work having error of can't access to it.. However, every end-user couldn't add to registry one-by-one.

@yanglr
Copy link
Author

@yanglr yanglr commented May 31, 2019

@SJang1
I guess you built the code in Debug mode, please change to Release mode, see below:
image

@SJang1
Copy link

@SJang1 SJang1 commented May 31, 2019

@yanglr
Already Built in Release.
image

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented May 31, 2019

For the record, I think we'd prefer that the terminal automatically registers this shortcut on behalf of the user.

@yanglr
Copy link
Author

@yanglr yanglr commented Jun 1, 2019

@zadjii-msft
Cool, great !

@yanglr yanglr closed this Jun 3, 2019
@msftbot msftbot bot added the Needs-Tag-Fix label Jun 3, 2019
@zadjii-msft zadjii-msft reopened this Jun 3, 2019
msftbot bot pushed a commit that referenced this issue May 28, 2020
## Summary of the Pull Request

![image](https://user-images.githubusercontent.com/18356694/82586680-94447680-9b5d-11ea-9cf1-a85d2b32db10.png)

I went with the simple option - just open the Terminal with the default profile in the selected directory. I'd love to add another entry for "Open Terminal here with Profile...", but that's going to be follow-up work, once we sort out pulling the Terminal Settings into their own dll.

## References
* I'm going to need to file a bunch of follow-ups on this one.
  - We should add another entry to let the user select which profile
  - We should add the icon - I've got to do it in `dllname.dll,1` format, which is annoying.
  - These strings should be localized.
  - Should this only appear on <kbd>Shift</kbd>+right click? Probably! However, I don't know how to do that.
* [A Win7 Explorer Command Sample](https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appshellintegration/ExplorerCommandVerb) which hasn't aged well
* [cppwinrt tutorial](https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/author-coclasses) on using COM in cppwinrt
* [This is PowerToys' manifest](https://github.com/microsoft/PowerToys/blob/d2a60c7287eb5667b5282a519c92b759664c9e30/installer/MSIX/appxmanifest.xml#L53-L65) and then [their implementation](https://github.com/microsoft/PowerToys/blob/d16ebba9e0f06e7a0d41d981aeb1fd0a78192dc0/src/modules/powerrename/dll/PowerRenameExt.cpp) which were both helpful
* [This ](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#instructions) was the sample I followed for how to actually set up the manifest, with the added magic that [`desktop5` lets you specify "Directory"](https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-desktop5-itemtype)

## PR Checklist
* [x] Closes #1060
* [x] I work here
* [ ] Tests added/passed
* [n/a] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments

This adds a COM class that implements `IExplorerCommand`, which is what lets us populate the context menu entry. We expose that type through a new DLL that is simply responsible for the shell extension, so that explorer doesn't need to load the entire Terminal just to populate that entry.

The COM class is tied to the application through some new entries in the manifest. The Clsid values are IMPORTANT - they must match the UUID of the implementation type. However, the `Verb` in the manifest didn't seem important.
@msftbot msftbot bot added Resolution-Fix-Committed and removed In-PR labels May 28, 2020
jelster pushed a commit to jelster/terminal that referenced this issue May 28, 2020
)

## Summary of the Pull Request

![image](https://user-images.githubusercontent.com/18356694/82586680-94447680-9b5d-11ea-9cf1-a85d2b32db10.png)

I went with the simple option - just open the Terminal with the default profile in the selected directory. I'd love to add another entry for "Open Terminal here with Profile...", but that's going to be follow-up work, once we sort out pulling the Terminal Settings into their own dll.

## References
* I'm going to need to file a bunch of follow-ups on this one.
  - We should add another entry to let the user select which profile
  - We should add the icon - I've got to do it in `dllname.dll,1` format, which is annoying.
  - These strings should be localized.
  - Should this only appear on <kbd>Shift</kbd>+right click? Probably! However, I don't know how to do that.
* [A Win7 Explorer Command Sample](https://github.com/microsoft/Windows-classic-samples/tree/master/Samples/Win7Samples/winui/shell/appshellintegration/ExplorerCommandVerb) which hasn't aged well
* [cppwinrt tutorial](https://docs.microsoft.com/en-us/windows/uwp/cpp-and-winrt-apis/author-coclasses) on using COM in cppwinrt
* [This is PowerToys' manifest](https://github.com/microsoft/PowerToys/blob/d2a60c7287eb5667b5282a519c92b759664c9e30/installer/MSIX/appxmanifest.xml#L53-L65) and then [their implementation](https://github.com/microsoft/PowerToys/blob/d16ebba9e0f06e7a0d41d981aeb1fd0a78192dc0/src/modules/powerrename/dll/PowerRenameExt.cpp) which were both helpful
* [This ](https://docs.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-extensions#instructions) was the sample I followed for how to actually set up the manifest, with the added magic that [`desktop5` lets you specify "Directory"](https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/uapmanifestschema/element-desktop5-itemtype)

## PR Checklist
* [x] Closes microsoft#1060
* [x] I work here
* [ ] Tests added/passed
* [n/a] Requires documentation to be updated

## Detailed Description of the Pull Request / Additional comments

This adds a COM class that implements `IExplorerCommand`, which is what lets us populate the context menu entry. We expose that type through a new DLL that is simply responsible for the shell extension, so that explorer doesn't need to load the entire Terminal just to populate that entry.

The COM class is tied to the application through some new entries in the manifest. The Clsid values are IMPORTANT - they must match the UUID of the implementation type. However, the `Verb` in the manifest didn't seem important.
@Xuz99
Copy link

@Xuz99 Xuz99 commented May 30, 2020

Thank you to everyone who commented a solution and different approaches to apply this correctly. I got it working with Console 2. Using the "Open here" with the flag -d . worked prefect.

@foremtehan

This comment has been minimized.

@DHowett

This comment has been minimized.

@Vlad412
Copy link

@Vlad412 Vlad412 commented Jun 6, 2020

@miniksa @zadjii-msft @DHowett-MSFT @factormystic @ChrisGuzak

I solved the issue now, it could be closed. Thanks a lot to all who involved into this discussion.

Step 0:

Test if two constants below works well which will be used in following other steps.

echo %USERPROFILE%

echo %LOCALAPPDATA%

If everything works well here, then these two constants can be used directly in other below steps.

Or please perform following replacements in below steps:

%USERPROFILE% → C:\Users\[userName]
%LOCALAPPDATA% → C:\Users\[userName]\AppData\Local

Here [userName] represents your user name,for instance, mine is Bruce.

Step 1:
Run below stuff in CMD:

mkdir "%USERPROFILE%\AppData\Local\terminal"

image

Step 2:
Copy the windows terminal icon to the folder %USERPROFILE%\AppData\Local\terminal, the icon can be obtained in https://github.com/yanglr/WindowsDevTools/tree/master/awosomeTerminal/icons whose file name is wt_32.ico.

Step 3:
Save follwing content as wt.reg, then run as administrator.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt]
@="Windows terminal here"
"Icon"="%USERPROFILE%\\AppData\\Local\\terminal\\wt_32.ico"

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"

To be noted, if the exe obtained after building code by yourself is wtd.exe, you need to change the above wt.exe to wtd.exe in the above registry.

Step 4:
Test
image

I had a problem with this solution, some permission issues, if it can help someone
replace
@="%LOCALAPPDATA%\\Microsoft\\WindowsApps\\wt.exe"
with
@="C:\\Users\\YOURUSERNAME\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe -d ."

@Wakeful-Cloud
Copy link

@Wakeful-Cloud Wakeful-Cloud commented Jun 12, 2020

From my understanding, percent-encoded environment-variables must use the expandable string type (REG_EXPAND_SZ) in order to be correctly interpreted which is why I believe some of the other solutions don't fully work1. I created the below Registry script which uses expandable strings so you don't have to change the username however, you probably want to change the icon path.

I also added an action/option to open as an administrator.

Windows Registry Editor Version 5.00

;Binary data is just UTF16 (LE) split every 2 bytes with a comma
;Conversion done with https://onlineutf8tools.com/convert-utf8-to-utf16?hex=true&little-endian=true&space=false&chain=split-string%253Fsplit-by-length%253Dtrue%2526separator%253D%252C

;User action
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminal]
@="Open Terminal here"
;"Icon"="%USERPROFILE%\Pictures\Icons\terminal.ico" (Location to ICO or comment out to hide icon)
"Icon"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,50,00,69,00,63,00,74,00,75,00,72,00,65,00,73,00,5c,00,49,00,63,00,6f,00,6e,00,73,00,5c,00,74,00,65,00,72,00,6d,00,69,00,6e,00,61,00,6c,00,2e,00,69,00,63,00,6f,00

;User action command
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminal\command]
;@="%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe -d ."
@=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,00,54,00,41,00,25,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,41,00,70,00,70,00,73,00,5c,00,77,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00,64,00,20,00,2e,00

;Admin action
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminalAdmin]
@="Open Terminal here (Admin)"
;Show the UAC shield on the action
"HasLUAShield"=""
;"Icon"="%USERPROFILE%\Pictures\Icons\terminal.ico" (Location to ICO or comment out to hide icon)
"Icon"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,50,00,69,00,63,00,74,00,75,00,72,00,65,00,73,00,5c,00,49,00,63,00,6f,00,6e,00,73,00,5c,00,74,00,65,00,72,00,6d,00,69,00,6e,00,61,00,6c,00,2e,00,69,00,63,00,6f,00

;Admin action command
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminalAdmin\command]
@="PowerShell -WindowStyle Hidden -Command \"Start-Process wt -ArgumentList '-d','.' -Verb runAs\""
  1. https://superuser.com/a/599025

@ghost
Copy link

@ghost ghost commented Jun 15, 2020

From my understanding, percent-encoded environment-variables must use the expandable string type (REG_EXPAND_SZ) in order to be correctly interpreted which is why I believe some of the other solutions don't fully work1. I created the below Registry script which uses expandable strings so you don't have to change the username however, you probably want to change the icon path.

I also added an action/option to open as an administrator.

Windows Registry Editor Version 5.00

;Binary data is just UTF16 (LE) split every 2 bytes with a comma
;Conversion done with https://onlineutf8tools.com/convert-utf8-to-utf16?hex=true&little-endian=true&space=false&chain=split-string%253Fsplit-by-length%253Dtrue%2526separator%253D%252C

;User action
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminal]
@="Open Terminal here"
;"Icon"="%USERPROFILE%\Pictures\Icons\terminal.ico" (Location to ICO or comment out to hide icon)
"Icon"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,50,00,69,00,63,00,74,00,75,00,72,00,65,00,73,00,5c,00,49,00,63,00,6f,00,6e,00,73,00,5c,00,74,00,65,00,72,00,6d,00,69,00,6e,00,61,00,6c,00,2e,00,69,00,63,00,6f,00

;User action command
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminal\command]
;@="%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe -d ."
@=hex(2):25,00,4c,00,4f,00,43,00,41,00,4c,00,41,00,50,00,50,00,44,00,41,00,54,00,41,00,25,00,5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,41,00,70,00,70,00,73,00,5c,00,77,00,74,00,2e,00,65,00,78,00,65,00,20,00,2d,00,64,00,20,00,2e,00

;Admin action
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminalAdmin]
@="Open Terminal here (Admin)"
;Show the UAC shield on the action
"HasLUAShield"=""
;"Icon"="%USERPROFILE%\Pictures\Icons\terminal.ico" (Location to ICO or comment out to hide icon)
"Icon"=hex(2):25,00,55,00,53,00,45,00,52,00,50,00,52,00,4f,00,46,00,49,00,4c,00,45,00,25,00,5c,00,50,00,69,00,63,00,74,00,75,00,72,00,65,00,73,00,5c,00,49,00,63,00,6f,00,6e,00,73,00,5c,00,74,00,65,00,72,00,6d,00,69,00,6e,00,61,00,6c,00,2e,00,69,00,63,00,6f,00

;Admin action command
[HKEY_CLASSES_ROOT\Directory\Background\shell\WindowsTerminalAdmin\command]
@="PowerShell -WindowStyle Hidden -Command \"Start-Process wt -ArgumentList '-d','.' -Verb runAs\""
  1. https://superuser.com/a/599025

Hey thanks for this, I didn't end up using this because it pops up a Windows PowerShell window when launching in an elevated fashion however it got me to look deeper into this and I've made my own repository with an easy install script for anyone else who desires context menu entries for Windows Terminal.

@lextm
Copy link

@lextm lextm commented Jun 16, 2020

For future readers of this long thread,

  • Microsoft decided to include its own Windows Explorer context menu items. That's why this issue was closed. However, due to their release cycle this won't land on your machine (via Microsoft Store for Windows 10) in a few weeks (or months). So far, they developed a simple shell extension with some core functionality.

  • If you really need context menus at this moment, you have to add such menu items on your own using one of the methods in this long thread. To summarize,

    • Import registry keys.
    • Use some batch files. (like this)
    • Use some PowerShell scripts. (like this)

Whatever you choose, report issues to the owners of those repo so they can fix them.

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Jun 16, 2020

  • However, due to their release cycle this won't land on your machine (via Microsoft Store for Windows 10) in a few weeks (or months)

Oh it'll definitely be sooner than months 😉

@msftbot
Copy link
Contributor

@msftbot msftbot bot commented Jun 18, 2020

🎉This issue was addressed in #6100, which has now been successfully released as Windows Terminal Preview v1.1.1671.0.🎉

Handy links:

@jack1142
Copy link

@jack1142 jack1142 commented Jun 18, 2020

Shouldn't the Store Download link to Windows Terminal Preview (https://www.microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)? 🤔

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Jun 18, 2020

@DHowett oh no, we'll need to update the bot

@ghost
Copy link

@ghost ghost commented Jun 18, 2020

Seems as though I'll still be using my batch script for now as the vanilla one doesn't include an elevated option, I'm sure with more time the vanilla version will get more options and or features though, big thanks to the guy who submitted the pull request!

@DHowett
Copy link
Member

@DHowett DHowett commented Jun 18, 2020

Huh, we absolutely will need to update the bot. Lol.

@psxlover
Copy link

@psxlover psxlover commented Jun 18, 2020

Sorry for the off topic message, but if you have installed both the release version and the preview one, which would be invoked when running wt?

@jack1142
Copy link

@jack1142 jack1142 commented Jun 18, 2020

I'm guessing whatever you have set in App execution aliases in Windows's settings:
image

@DHowett
Copy link
Member

@DHowett DHowett commented Jun 18, 2020

Yep.

@musm
Copy link

@musm musm commented Jun 18, 2020

Would be nice if the terminal icon was included as well in the context menu

@zadjii-msft
Copy link
Member

@zadjii-msft zadjii-msft commented Jun 18, 2020

Would be nice if the terminal icon was included as well in the context menu

Hey wadda ya know, that's #6246.

Please for the love of everyone else on this issue (all 111 of you), please check these issues:
https://github.com/microsoft/terminal/issues?q=is%3Aopen+is%3Aissue+label%3AArea-ShellExtension

before commenting on "man it'd be cool if the context menu did..."

@microsoft microsoft locked as resolved and limited conversation to collaborators Jun 18, 2020
@miniksa
Copy link
Member

@miniksa miniksa commented Jun 19, 2020

Shouldn't the Store Download link to Windows Terminal Preview (microsoft.com/store/apps/9n8g5rfz9xk3?cid=storebadge&ocid=badge)? 🤔

@DHowett oh no, we'll need to update the bot

Huh, we absolutely will need to update the bot. Lol.

Got it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area-User Interface Help Wanted Issue-Feature Product-Terminal Resolution-Fix-Committed
Projects
None yet
Development

Successfully merging a pull request may close this issue.