Win7/10/11 禁止文件或文件夹联网(自动提权)
使用方法:把文件或文件夹拖放到BAT文件内
@echo off
if "%~1"=="" exit
REM 下面一行“=”等号右边的值为“True”时:只针对exe运行程序;其值为“False”时:针对任意文件。
set bEXEonly=True
REM 非管理员身份自动提权
Dism.exe>nul 2>nul
if %errorlevel% neq 0 goto Elevate
goto admin
:Elevate
if exist "C:\Windows\SysWOW64\ntdll.dll" (
set theExePath=%~dp0elevate-1.3.0-redist\bin.x86-64\elevate.exe
) else if exist "C:\Windows\System32\ntdll.dll" (
set theExePath=%~dp0elevate-1.3.0-redist\bin.x86-32\elevate.exe
)
if exist "%theExePath%" (
"%theExePath%" -c "%~0" "%~1"
)
exit
:admin
if not exist "%~dp0ruleNames\" md "%~dp0ruleNames"
REM Windows防火墙属性的默认设置(allprofiles=domainprofile+privateprofile+publicprofile)
netsh advfirewall set allprofiles state on
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound
REM 拖入的是一个文件夹目录
if exist "%~1\" (
REM 遍历文件夹下所有文件(含子文件夹下的文件)
if "%bEXEonly%"=="True" (
for /r "%~1\" %%i in ("*.exe") do (
netsh advfirewall firewall add rule name="!!! %date:~0,4%%date:~5,2%%date:~8,2%(%%~ni)" dir=out action=block enable=yes profile=any localip=any remoteip=any program="%%~i"
echo %%~i>>"%~dp0ruleNames\!!! %date:~0,4%%date:~5,2%%date:~8,2%(%%~ni).txt"
if not defined bFilesInPath set "bFilesInPath=True"
)
) else if "%bEXEonly%"=="False" (
for /r "%~1\" %%i in ("*.*") do (
netsh advfirewall firewall add rule name="!!! %date:~0,4%%date:~5,2%%date:~8,2%(%%~ni)" dir=out action=block enable=yes profile=any localip=any remoteip=any program="%%~i"
echo %%~i>>"%~dp0ruleNames\!!! %date:~0,4%%date:~5,2%%date:~8,2%(%%~ni).txt"
if not defined bFilesInPath set "bFilesInPath=True"
)
)
if not defined bFilesInPath exit
goto End
)
REM 拖入的是一个文件
if "%bEXEonly%"=="True" if /i "%~x1" NEQ ".exe" exit
netsh advfirewall firewall add rule name="!!! %date:~0,4%%date:~5,2%%date:~8,2%(%~n1)" dir=out action=block enable=yes profile=any localip=any remoteip=any program="%~1"
echo %~1>>"%~dp0ruleNames\!!! %date:~0,4%%date:~5,2%%date:~8,2%(%~n1).txt"
:End
echo.
echo 【操作完成】,按任意键退出....
echo.
pause>nul
exit
删除所有规则(仅删除由该BAT创建的全部规则)
@echo off
REM 需右键以管理员身份运行此批处理
REM 非管理员身份自动退出
Dism.exe>nul 2>nul
if %errorlevel% neq 0 exit
if exist "%~dp0ruleNames\" (
for %%i in ("%~dp0ruleNames\*.txt") do (
netsh advfirewall firewall delete rule name="%%~ni"
)
REM Windows防火墙属性的默认设置(allprofiles=domainprofile+privateprofile+publicprofile)
netsh advfirewall set allprofiles state on
netsh advfirewall set allprofiles firewallpolicy blockinbound,allowoutbound
del /f /q "%~dp0ruleNames\*.txt"
echo.
echo 【操作完成!】
)
echo.
echo 按任意键退出....
echo.
pause>nul
exit
查看或手动删除规则
@echo off
REM 打开“C:\Windows\System32\WF.msc”
if exist "%systemroot%\System32\WF.msc" (
start "" "%systemroot%\System32\WF.msc"
)
exit
版权申明
本文系作者 @技术狂人张大胆 原创发布在AP135 乐享生活网站点。未经许可,禁止转载。
评论