好库网 好库网首页 | 我的好库
好饱的专栏

DOS命令行批处理设置允许程序通过防火墙

发布者:好饱
发布日期:2020-3-18 21:32:00   更新日期:2020-3-18 21:39:00
阅读次数:1700
评分:4.80
介绍:命令行方式修改防火墙,允许程序通过。
正文:

因为操作系统版本不同,命令有所区别,所以需要先判断版本,转到old和new分支,代码如下:

@echo off
set CD="D:\Program Files (x86)\DingDing"
for /f "tokens=4,5 delims=. " %%a in ('ver') do if %%a%%b geq 60 goto new

:old
cmd /c netsh firewall delete allowedprogram program="%CD%\DingtalkLauncher.exe" profile=ALL
cmd /c netsh firewall add allowedprogram program="%CD%\DingtalkLauncher.exe" name="DingtalkLauncher" ENABLE
cmd /c netsh firewall add allowedprogram program="%CD%\DingtalkLauncher.exe" name="DingtalkLauncher" ENABLE profile=ALL
goto end
:new
cmd /c netsh advfirewall firewall delete rule name="DingtalkLauncher"
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=tcp enable=yes profile=public
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=udp enable=yes profile=public
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=tcp enable=yes profile=domain
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=udp enable=yes profile=domain
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=tcp enable=yes profile=private
cmd /c netsh advfirewall firewall add rule name="DingtalkLauncher" dir=in action=allow program="%CD%\DingtalkLauncher.exe" protocol=udp enable=yes profile=private
:end

评论 [发表评论]
账号 密码 还没帐号呢,现在注册一个?

免责声明:好库网所展示的信息由买卖双方自行提供,其真实性、准确性和合法性由信息发布人负责。好库网不提供任何保证,并不承担任何法律责任。