How can I get batch files to run through the new Windows Terminal? [closed]
You can have this behaviour on double click by changing HKEY_CLASSES_ROOT\batfile\shell\open\command
default value from:
"%1" %*
to:
"C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*
or by using ftype
command:
ftype batfile="C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*
You have to change <user>
with the current user name directory and of course, this wt.exe
path (C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\
) is if you've installed Windows Terminal from Microsoft Store, if you haven't, then you have to find the path to wt.exe
and use that instead. Windows enviroment variables %LOCALAPPDATA%
and %USERPROFILE%
did not work for me, so I'm using full path here.
You can create a registry entry to have an option to opem a BAT
file using Windows Terminal and having it running with CMD
:
- Open
regedit
and navigate toHKEY_CLASSES_ROOT\batfile\shell
key. - Create a key with the name
wtopen
and the default valueOpen with Windows Terminal
:
- Create a subkey
HKEY_CLASSES_ROOT\batfile\shell\wtopen\command
with the default value:"C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*
And now you'll have a new entry "Open with Windows Terminal" when you right click on BAT
files and when you click it it will open a new Windows Terminal with a Command Prompt panel running the selected batch file:
Tested with Windows Terminal 0.11.1121.0
The default name for the Command Prompt (cmd
) profile is "Command Prompt". You'll have to change it using the -p "<name>"
parameter if you have other name than the default.
I've been looking for this for at least a year, today I finally found a solution..In the Microsoft Forum an Advisor Said:
.Bat extension is a Command Prompt executable format.It would not support in the New Windows Terminal as I have checked.
Fortunately this is wrong, I found a way to set the new Windows Terminal as Default:
Just create a .reg file with this code, (replacing "Marco" with your username) and run it:
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\batfile\shell\open\command]@="\"C:\\Users\\Marco\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"%1\""
You also need to edit the windows terminal settings.json and change the default:
"startingDirectory": "%USERPROFILE%"
to
"startingDirectory": "."
If you don't do this it won't work because it tries to run it inside the user folder and not in the current!
The other answers work, but I also wanted batch files to open as a new tab if Windows Terminal is already open and allow scripts without absolute paths:
Open the Registry Editor and navigate to this key:
Computer\HKEY_CLASSES_ROOT\batfile\shell\open\command
Then modify the (Default)
value to the following:
wt.exe -w 0 new-tab -d . "%1" %*
where the -w 0
argument specifies to open in the first or existing window in a new-tab
at the current working directory of the file: -d .
Tip: if you have a batch file set up to silently run in the background that you don't want popping up, just rename it from .bat
to .cmd
!