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

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

问题描述

由于一次运行多个批处理文件,我倾向于一次打开大量 cmd 提示,因此我认为新的 Windows 终端将是一种使用选项卡整理内容的巧妙方法.

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 终端实例内的 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 终端,启动一个 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.

推荐答案

您可以通过将 HKEY_CLASSES_ROOTatfileshellopencommand 默认值从以下位置更改为双击来实现此行为:

You can have this behaviour on double click by changing HKEY_CLASSES_ROOTatfileshellopencommand default value from:

"%1" %*

到:

"C:Users<user>AppDataLocalMicrosoftWindowsAppswt.exe" -p "Command Prompt" "%1" %*

或使用 ftype 命令:

ftype batfile="C:Users<user>AppDataLocalMicrosoftWindowsAppswt.exe" -p "Command Prompt" "%1" %*

您必须将 更改为当前用户名目录,当然还有这个wt.exe 路径(C:Users<user>AppDataLocalMicrosoftWindowsApps) 是如果你已经从 Microsoft Store 安装了 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>AppDataLocalMicrosoftWindowsApps) 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 终端来运行 BAT 文件并使其与 CMD 一起运行:

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_ROOTatfileshell 键.
  2. 创建一个名为 wtopen 和默认值 Open with Windows Terminal 的密钥:
  1. Open regedit and navigate to HKEY_CLASSES_ROOTatfileshell key.
  2. Create a key with the name wtopen and the default value Open with Windows Terminal:

  1. 使用默认值创建子项 HKEY_CLASSES_ROOTatfileshellwtopencommand:
"C:Users<user>AppDataLocalMicrosoftWindowsAppswt.exe" -p "Command Prompt" "%1" %*

现在您将拥有一个新条目使用 Windows 终端打开",当您右键单击 BAT 文件时,单击它会打开一个新的Windows 终端,带有运行所选批处理文件的命令提示符面板:

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:

使用 Windows 终端 0.11.1121.0 测试

命令提示符 (cmd) 配置文件的默认名称是命令提示符".如果您有其他名称而不是默认名称,则必须使用 -p "" 参数更改它.

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.

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

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