通过CMD命令录入“netsh advfirewall firewall add rule” 就会获取到有帮助内容,里面正好有设置端口的例子。
Windows防火墙其实是个好东西,但是好像很少有人好好利用起来,这次简单说说利用Windows防火墙阻止程序联网。
记得批处理里面是先删除再添加的,你注释掉添加那一句就只是删除了
netsh advfirewall firewall del rule name=%%i>nul 2>nul
netsh advfirewall firewall add rule name=”%%i” program=%%j action=block dir=out>nul
@echo off
setlocal ENABLEDELAYEDEXPANSION
mode con: cols=65 lines=25
color 0a
rem 批处理获取管理员权限
:-------------------------------------
%1 mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas",1)(window.close)&&exit /b
CD /D "%~dp0"
:-------------------------------------
::添加阻止程序出站规则
(
echo "Office_OfficeClickToRun","%ProgramFiles%\Common Files\microsoft shared\ClickToRun\OfficeClickToRun.exe"
echo "Office_msoia","%ProgramFiles%\Microsoft Office\root\Office16\msoia.exe"
echo "Office_WINWORD","%ProgramFiles%\Microsoft Office\root\Office16\WINWORD.EXE"
echo "Office_EXCEL","%ProgramFiles%\Microsoft Office\root\Office16\EXCEL.EXE"
echo "Office_POWERPNT","%ProgramFiles%\Microsoft Office\root\Office16\POWERPNT.EXE"
echo "Office_VISIO","%ProgramFiles%\Microsoft Office\root\Office16\VISIO.EXE"
echo "Office_WINPROJ","%ProgramFiles%\Microsoft Office\root\Office16\WINPROJ.EXE"
echo "Office_MSPUB","%ProgramFiles%\Microsoft Office\root\Office16\MSPUB.EXE"
echo "Office_MSACCESS","%ProgramFiles%\Microsoft Office\root\Office16\MSACCESS.EXE"
echo "AutoCAD_LMU","%ProgramFiles%\Common Files\Autodesk Shared\AdLM\R11\LMU.exe"
echo "AutoCAD_DADispatcherService","C:\Program Files\Autodesk\AutoCAD 2016\DADispatcherService.exe"
echo "AutoCAD_acad","C:\Program Files\Autodesk\AutoCAD 2016\acad.exe"
)>list.txt
FOR /F "usebackq tokens=1,2 delims=," %%i in ( list.txt ) do (
netsh advfirewall firewall del rule name="%%i">nul 2>nul
netsh advfirewall firewall add rule name="%%i" program=%%j action=block dir=out>nul
echo 阻止%%i程序出站规则已添加
)
del list.txt
::添加阻止服务出站规则
(
echo "Windows Update","wuauserv"
)>list.txt
set svchost_exe="%%systemroot%%\system32\svchost.exe"
FOR /F "usebackq tokens=1,2 delims=," %%i in ( list.txt ) do (
netsh advfirewall firewall del rule name=%%i>nul 2>nul
netsh advfirewall firewall add rule name=%%i service=%%j action=block dir=out program="%svchost_exe%">nul
echo 阻止%%i服务出站规则已添加
)
del list.txt
pause
历史上的今天
2022年:Directory Lister魔改Xdir v1.3.8发布(16条评论)
2015年:解决Windows8.1/10下安装secoway vpn client后启动时报虚拟网卡无法启动(0条评论)
请博主喝杯咖啡呢,谢谢^_^
如果本文“对您或有帮助”,欢迎随意打赏,以资鼓励继续创作!
原创文章《批处理利用Windows防火墙阻止程序和服务联网》,作者:笔者 徐哲,未经允许不得转载。
转载或复制时,请注明出处:https://www.xuxiaokun.com/229.html,本文由 Mr.xu 博客网 整理。
本站资源下载仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。