For AI agents: the complete documentation index is available at https://www.tteam.icu/llms.txt, the full documentation bundle is available at https://www.tteam.icu/llms-full.txt, and this page is available as Markdown at https://www.tteam.icu/ops/windows/bat%E5%91%BD%E4%BB%A4.md.

bat命令

Tip

在最开始加上@echo off可以确保从文件开始执行起,所有的后续命令都不会显示在屏幕上

在结尾加上pause命令可以让脚本程序暂停, 会打印输出 “请按任意键继续...”字样。

转发端口

:: 清除所有转发
netsh interface portproxy reset
:: 把192.168.1.1上的8080转发到本机的80端口
netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=80 connectaddress=192.168.1.1 connectport=8080
:: 删除80端口的转发
netsh interface portproxy delete v4tov4 listenaddress=0.0.0.0 listenport=80

获取变量/环境变量

echo %appname%