如何使批处理文件通过新的Windows终端运行? [英] How can I get batch files to run through the new Windows Terminal?

查看:780
本文介绍了如何使批处理文件通过新的Windows终端运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一次运行多个批处理文件时,我倾向于一次打开很多cmd提示,因此我认为新的Windows Terminal将是一种使用选项卡整理内容的好方法.

I tend to have a lot of cmd prompts open at a time from running multiple batch files at once, so I figured the new Windows Terminal would be a neat way to tidy things up with tabs.

问题是,我不太清楚如何将通过cmd实例运行批处理文件的默认行为更改为通过Windows Terminal实例内部的cmd实例运行所需的运行批处理文件.

Problem is, I can't quite figure out how to change the default behavior of running batch files through a cmd instance to the desired running batch files through a cmd instance that is inside of a Windows Terminal instance.

我能够轻松打开Windows Terminal,启动一个cmd实例,将cd切换到正确的目录,然后运行批处理文件.我只希望能够运行一个批处理文件,并通过Windows终端中的cmd提示符使它工作.

I'm able to easily open Windows Terminal, start a cmd instance, cd to the correct dir, and run the batch file.. but that's a lot of effort. I want to just be able to run a batch file, and have it work through a cmd prompt that's inside Windows Terminal.

推荐答案

通过从以下位置更改HKCR\batfile\shell\open\command默认值,您可以在双击时出现此行为:

You can have this behaviour on double click by changing HKCR\batfile\shell\open\command default value from:

"%1" %*

收件人:

"C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*

或使用ftype命令:

ftype batfile="C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*

您必须使用当前用户名目录更改<user>,当然,此wt.exe路径(C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\)是如果您已经从 Microsoft安装了 Windows Terminal 存储,如果尚未存储,则必须找到wt.exe的路径,并改用该路径. Windows环境变量%LOCALAPPDATA%%USERPROFILE%对我不起作用,因此我在这里使用完整路径.

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.

您可以创建一个注册表项,以使用Windows Terminal并使其与CMD文件一起运行来选择BAT文件:

You can create a registry entry to have an option to opem a BAT file using Windows Terminal and having it running with CMD:

  1. 打开regedit并导航至HKEY_CLASSES_ROOT\batfile\shell键.
  2. 使用名称wtopen和默认值Open with Windows Terminal创建密钥:

  1. Open regedit and navigate to HKEY_CLASSES_ROOT\batfile\shell key.
  2. Create a key with the name wtopen and the default value Open with Windows Terminal:

"C:\Users\<user>\AppData\Local\Microsoft\WindowsApps\wt.exe" -p "Command Prompt" "%1" %*

现在,当您右键单击BAT文件时,您将拥有一个新条目使用Windows终端打开" ,当您单击它时,它将打开一个新的 Windows终端 Command Promt 面板运行选定的批处理文件:

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 Promt panel running the selected batch file:

使用Windows Terminal 0.11.1121.0测试

命令提示符(cmd)配置文件的默认名称为命令提示符" .如果您使用的名称不是默认名称,则必须使用-p "<name>"参数进行更改.

The default name for the Command Promt (cmd) profile is "Command Promt". You'll have to change it using the -p "<name>" parameter if you have other name than the default.

这篇关于如何使批处理文件通过新的Windows终端运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆