Add “Open Admin Windows Terminal Command Prompt” to the Explorer context menu in Windows 10 (with keyboard shortcuts and includes Windows PowerShell and Ubuntu)
Click here for the TL;DR version. Here is a GitHub repo with REG files that you can import in case you don't want to go through all of this yourself. I also included a REG file that removes the options. Make sure you read the README.
Windows Terminal is available in the Microsoft Store. It is a terminal application that features tabs, and can open instances of Windows PowerShell, Command Prompt, WSL (Linux terminal), and Azure Cloud Shell.
If you are interested in adding an option to the Explorer context menu for opening an admin Command Prompt in a target folder, then you might be interested in adding a similar option for opening such a folder in a Windows Terminal Command Prompt (or PowerShell or WSL).
Here's how it works. We are going to add this option for the context menu in the background of the explorer window, on an actual folder, and on a file.
Here are the steps for doing this manually:
You can always just download REG the files from the Github repo linked here and above instead.
KNOWN ISSUE: When trying to open a Windows Terminal instance on the root folder of a drive, instead of opening the root folder, it will open the user profile folder. I will update this post if I ever find a fix. I am sure that there is some PowerShell scripting that can be put together to handle this situation, and that the command would still be one long line.
WARNING: This procedure involves modifying the Windows registry and modifying permissions. You assume all responsibility for whatever happens. Screwing up anything in here might prevent Windows from starting or working properly. If you are not comfortable with modifying the registry, I would suggest stopping now. If you choose to continue, create a restore point and make a full backup of your machine. Also export the registry keys per the instructions below.
NOTE: You will need to follow Steps 3-10 THREE TIMES! The first time is for the folder context-menu (right-clicking on a folder in an Explorer window), the second time is for the background context-menu (right-clicking on the background of an Explorer window), and the third time is for file context menu (right-clicking on a file in an Explorer window). Just repeat the steps and use the indicated registry path in Step 3 and the indicated command in Step 10.
NOTE 2: These instructions include a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press t to select the option. If you are in a menu with more than one option assigned to t, you will have to press t until the option you want is selected, and then press Enter to select it.
1. Install Windows Terminal from the Microsoft Store.
2. After installing the app, download the Windows Terminal icon from the project on GitHub or right-click and save the image below and save it to the app's package folder located here:
%localappdata%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState
So far, I have not found an easy way to make the menu icon be consistent without having to manually download it as the path to the exe changes every time the app is updated and none of the regular shortcuts include the icon.
The problem with this approach is that you will have to manually update the icon if it is ever changed in future versions. Or if you don't care about the icon, you can leave it as is. The URL is given below:
https://raw.githubusercontent.com/microsoft/terminal/master/res/terminal.ico
3. Open the Registry Editor by clicking on start and typing: regedit
Click on the Registry Editor option that appears, or press Enter.
4. Go to the following location using the address bar at the top of the Registry Editor window:
For the folder context-menu: (right-clicking on a folder in an Explorer window)
- HKEY_CLASSES_ROOT\Directory\shell
For the background context-menu: (right-clicking on the background of an Explorer window)
- HKEY_CLASSES_ROOT\Directory\Background\shell
For the file context-menu: (right-clicking on a file in an Explorer window):
- HKEY_CLASSES_ROOT\*\shell
The rest of the instructions will be the same except for the last step.
5. BACK UP THE KEYS THAT WE WILL BE MODIFYING!
Right-click on the folder to which you just navigated, and click Export.
You will need to do this for both of the folders from Step 3.
Choose a location and name the file something that will describe what it is, such as directory_shell_backup.reg or directory_background_shell_backup.reg, and click Save.
6. After completing your export in Step 4, right-click on the shell folder, and select New, and then Key. Replace New Key #1 with runaswt.
If you are following the elevated prompt instructions, then use runaswtad.
7. Click on the folder that you just created. You will see a key labeled (Default). Double-click on it, and enter the following into the Value data field, and then click OK:
For the folder context-menu: (right-clicking on a folder in an Explorer window)
- Open in Windows &Terminal Command Prompt
For the background context-menu: (right-clicking on the background of an Explorer window)
- Open Windows &Terminal Command Prompt here
For the file context-menu: (right-clicking on a file in an Explorer window):
- Open Windows &Terminal Command Prompt at file location
You can be creative as I have been in the image in Step 6 below, as long as you know what the command actually does.
If you are following the elevated prompt instructions, then use something like:
For the folder context-menu:
- Open in Windows &Terminal Admin Command Prompt
For the background context-menu:
- Open Windows &Terminal Admin Command Prompt here
For the file context-menu:
- Open Windows &Terminal Admin Command Prompt at file location
NOTE: The & that appears before "Terminal" indicates that the letter that follows it can be used as a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press t to select the option. If you are in a menu with more than one option assigned to t, you will have to press t until the option you want is selected, and then press Enter to select it. You can also move the & to another character or add unique characters so you won't have to press Enter.
8. Right-click on the folder that you created, and select New, and then String Value. Enter the following as the name:
- NoWorkingDirectory
If you are following the elevated prompt instructions and want to use the Extended context menu (Shift + Right-click), then repeat this step using the name below:
- Extended
9. Right-click on the folder that you created, and select New, and then String Value. Enter the following as the name:
- Icon
Double-click on it, and enter the following as the value:
- %localappdata%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\terminal.ico
This will put the Windows Terminal icon that we downloaded in Step 2 into the dropdown to the left of the entry.
NOTE: As previously noted in Step 2, if the official icon ever changes, then the new icon will have to be downloaded and saved into the folder in Step 2. Or, if you don't really care about the icon, just leave it as is.
10. Right-click on the runaswt folder, and select New, and then Key. Give it the name below, and then click on it:
- command
11. Double-click the (Default) key, and enter the following into the field:
For the folder context-menu: (right-clicking on a folder in an Explorer window)
- cmd.exe /c start wt.exe -p "Command Prompt" -d "%1"
For the background context-menu: (right-clicking on the background of an Explorer window)
- cmd.exe /c start wt.exe -p "Command Prompt" -d "%V"
For the file context-menu: (right-clicking on a file in an Explorer window):
- cmd.exe /c start wt.exe -p "Command Prompt" -d "%w"
NOTE: These three commands use different variables for the folder, which is why the command for the folder context-menu ends with $1, the one for the background context-menu ends with $V, and the one for the file context-menu ends with %w
The variable V refers to the path of the Explorer window, rather than the path of the folder that was clicked. I found that variable by looking at other keys under HKEY_CLASSES_ROOTDirectoryBackgroundshellcmd and coming to the conclusion that it must be referring to the path of the window. Much later, I looked up this list of shell command variables.
If you are following the elevated prompt instructions, then use the commands below:
For the folder context-menu:
- powershell.exe -WindowStyle Hidden "Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','"""Command Prompt"""','-d','"""%1"""')"
For the background context-menu:
- powershell.exe -WindowStyle Hidden "Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','"""Command Prompt"""','-d','"""%V"""')"
For the file context-menu:
- powershell.exe -WindowStyle Hidden "Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','"""Command Prompt"""','-d','"""%w"""')"
NOTE: If you want to open Windows Powershell instead of Command Prompt, change Command Prompt to Windows Powershell. You can also use something like Ubuntu or Debian to open an Ubuntu or a Debian shell, depending upon what you have installed. You will have to use version with or without the number that you have installed on your machine. You will probably also want to change the menu string to reflect this change. Check out more command line options here. The REG files in the GitHub repo contain versions for Command Prompt, Windows PowerShell, and Ubuntu.
TL;DR
Here is a link to the GitHub repo with REG files that you can import in case you don't want to go through all of this yourself. I also included a REG file that removes the options.
NOTE: About the icon... If you want the Windows Terminal icon to appear in the menu, you will need to download it and put it into the folder in Step 2 above. The path to the exe changes with every new version, and try as I might, I have not been able to find a consistent shortcut path to the exe that includes the icon. This means that if the official icon changes, you will need to download the new one and replace the one in the folder. Or you can just leave the old one if you don't care. The Windows PowerShell entries in the REG files on GitHub and in the block below use the regular powershell.exe icons.
NOTE 2: These instructions include a keyboard shortcut. If you use Shift+Right Click, Shift+Context Menu Key, or Shift+F10, you can press t to select the option. If you are in a menu with more than one option assigned to t, you will have to press t until the option you want is selected, and then press Enter to select it. You can also edit the menu string and move the & to another character or add unique characters so you don't have to press Enter.
NOTE 3: If you want to open Windows Powershell instead of Command Prompt, change Command Prompt in the command string to Windows Powershell. You can also use something like Ubuntu to open an Ubuntu shell. You will probably have to use version number that you have installed on your machine if you have more than one. You will probably also want to change the menu string to reflect this change. Check out more command line options here.
There are two versions in the GitHub repo. You should only import one of them. One of them puts both the regular and admin options into the regular context menu. The other (with "-shift" in the filename) puts the admin terminal option into the Extended (Shift + Right-click) context menu.
You can also just copy the block below and paste it into a new file with the REG extension, such as wt-cmd-prompt-combined.reg. The block below puts the admin option into the Extended context menu.
If you use the block below, to see the admin terminal option in the Explorer context menu, use Shift+Right-click. This version also includes the Windows PowerShell and Ubuntu options!
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswt]
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
@="Open Windows &Terminal Command Prompt here"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswt\command]
@="cmd.exe /c start wt.exe -p \"Command Prompt\" -d \"%V\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswt]
@="Open in Windows &Terminal Command Prompt"
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswt\command]
@="cmd.exe /c start wt.exe -p \"Command Prompt\" -d \"%1\""
[HKEY_CLASSES_ROOT\*\shell\1runaswt]
@="Open Windows &Terminal Command Prompt at file location"
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
[HKEY_CLASSES_ROOT\*\shell\1runaswt\command]
@="cmd.exe /c start wt.exe -p \"Command Prompt\" -d \"%w\""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtad]
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
@="Open Admin Windows &Terminal Command Prompt here"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Command Prompt\"\"\"','-d','\"\"\"%V\"\"\"')\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtad]
@="Open in Admin Windows &Terminal Command Prompt"
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Command Prompt\"\"\"','-d','\"\"\"%1\"\"\"')\""
[HKEY_CLASSES_ROOT\*\shell\1runaswtad]
@="Open Admin Windows &Terminal Command Prompt at file location"
"Icon"="%localappdata%\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\terminal.ico"
"Extended"=""
[HKEY_CLASSES_ROOT\*\shell\1runaswtad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Command Prompt\"\"\"','-d','\"\"\"%w\"\"\"')\""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtps]
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
@="Open Windows Terminal Power&Shell here"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtps\command]
@="cmd.exe /c start wt.exe -p \"Windows PowerShell\" -d \"%V\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtps]
@="Open in Windows Terminal Power&Shell"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtps\command]
@="cmd.exe /c start wt.exe -p \"Windows PowerShell\" -d \"%1\""
[HKEY_CLASSES_ROOT\*\shell\1runaswtps]
@="Open Windows Terminal Power&Shell at file location"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe"
[HKEY_CLASSES_ROOT\*\shell\1runaswtps\command]
@="cmd.exe /c start wt.exe -p \"Windows PowerShell\" -d \"%w\""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtpsad]
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe,1"
@="Open Admin Windows Terminal Power&Shell here"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtpsad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Windows PowerShell\"\"\"','-d','\"\"\"%V\"\"\"')\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtpsad]
@="Open in Admin Windows Terminal Power&Shell"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe,1"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtpsad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Windows PowerShell\"\"\"','-d','\"\"\"%1\"\"\"')\""
[HKEY_CLASSES_ROOT\*\shell\1runaswtpsad]
@="Open Admin Windows Terminal Power&Shell at file location"
"Icon"="%SystemRoot%\\system32\\WindowsPowerShell\\v1.0\\powershell.exe,1"
[HKEY_CLASSES_ROOT\*\shell\1runaswtpsad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Windows PowerShell\"\"\"','-d','\"\"\"%w\"\"\"')\""
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtub]
"Icon"="%windir%\\System32\\wsl.exe"
@="Open Windows Terminal &Ubuntu Bash here"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtub\command]
@="cmd.exe /c start wt.exe -p \"Ubuntu\" -d \"%V\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtub]
@="Open in Windows Terminal &Ubuntu Bash"
"Icon"="%windir%\\System32\\wsl.exe"
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtub\command]
@="cmd.exe /c start wt.exe -p \"Ubuntu\" -d \"%1\""
[HKEY_CLASSES_ROOT\*\shell\1runaswtub]
@="Open Windows Terminal &Ubuntu Bash at file location"
"Icon"="%windir%\\System32\\wsl.exe"
[HKEY_CLASSES_ROOT\*\shell\1runaswtub\command]
@="cmd.exe /c start wt.exe -p \"Ubuntu\" -d \"%w\""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtubad]
"Icon"="%windir%\\System32\\wsl.exe"
@="Open Admin Windows Terminal &Ubuntu Bash here"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\1runaswtubad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Ubuntu\"\"\"','-d','\"\"\"%V\"\"\"')\""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtubad]
@="Open in Admin Windows Terminal &Ubuntu Bash"
"Icon"="%windir%\\System32\\wsl.exe"
"Extended"=""
"NoWorkingDirectory"=""
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\1runaswtubad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Ubuntu\"\"\"','-d','\"\"\"%1\"\"\"')\""
[HKEY_CLASSES_ROOT\*\shell\1runaswtubad]
@="Open Admin Windows Terminal &Ubuntu Bash at file location"
"Icon"="%windir%\\System32\\wsl.exe"
[HKEY_CLASSES_ROOT\*\shell\1runaswtubad\command]
@="powershell.exe -WindowStyle Hidden \"Start-Process -Verb RunAs cmd.exe -ArgumentList @('/c','start wt.exe','-p','\"\"\"Ubuntu\"\"\"','-d','\"\"\"%w\"\"\"')\""
"Extended"=""
"NoWorkingDirectory"=""
Double-click the REG file (either the one you created or the one in the repo files) to add the entries to the registry.
That's it!
Now you should be able to open the Windows Terminal Command Prompt (and/or Windows PowerShell and Ubuntu) from the context-menu of any explorer folder or window. If you don't see it right away, try rebooting.
Here is a list of all of the resources I used while researching and implementing this solution:
- How to return the 'Open command window here' option to Windows 10's context menu
- How to Launch Administrator Command Prompt in Windows 8 File Explorer
- Add “Open Windows Terminal Command Prompt” to the Explorer context menu in Windows 10
- Which special variables are available when writing a shell command for a context menu
- Document shell icons and their paths at GitHub
- Where can I find the Windows Terminal Icon? at GitHub
Here is a list of other useful links for Windows Terminal customization and configuration (I am not affiliated with any of these sites):
- How to Customize the New Windows Terminal App at HowToGeek
- Windows Terminal: The Complete Guide at SitePoint
- Profile settings in Windows Terminal at Microsoft Docs
- Using command-line arguments for Windows Terminal at Microsoft Docs
You must be logged in to post a comment.