@echo off set file_path="C:\Path\To\Your\File.exe" set rule_name="My Rule Name" set protocol=any
echo Adding %file_path% to Windows Firewall... netsh advfirewall firewall delete rule name=%rule_name% > nul echo Adding inbound rule... netsh advfirewall firewall add rule name=%rule_name% dir=in action=allow program=%file_path% enable=yes protocol=%protocol% localport=any > nul echo Adding outbound rule... netsh advfirewall firewall add rule name=%rule_name% dir=out action=allow program=%file_path% enable=yes protocol=%protocol% localport=any > nul echo Done!
如果您只需要添加入站规则或出站规则,请根据您的需求修改脚本中的 dir
参数为 in
(入站规则)或 out
(出站规则)。例如,如果您只需要添加入站规则,请将脚本更改为以下内容:
@echo off set file_path="C:\Path\To\Your\File.exe" set rule_name="My Rule Name" set protocol=TCP echo Adding %file_path% to Windows Firewall... netsh advfirewall firewall delete rule name=%rule_name% > nul echo Adding inbound rule... netsh advfirewall firewall add rule name=%rule_name% dir=in action=allow program=%file_path% enable=yes protocol=%protocol% localport=any > nul echo Done!
在set protocol=TCP 后面可以设置UDP还是同时,以及指定端口
(set protocol=any TCP 和 UDP)
(set local_port=8080 如果是指定端口)标签:EXE,protocol,name,Windows,防火墙,rule,echo,set,file From: https://www.cnblogs.com/stweily/p/17373409.html
以上记录方便写成脚本,对很多的设置这样就可以直接右点管理员运行一键搞定了。