@echo off
title Block all the exe file network connection
::automatic request Administrator
reg query HKU\S-1-5-20>nul 2>nul|| echo;CreateObject^("Shell.Application"^).ShellExecute "%~f0", "%*", "", "runas", 1 > "%temp%\getadmin.vbs" && cscript //b "%temp%\getadmin.vbs" && exit /b & del "%temp%\getadmin.vbs" /f /q>nul 

:home
cls
set /p exepath=input the directory location:
if not exist "%exepath%" (
    echo;input invalid
    pause>nul
    goto home
)

pushd %exepath%
for /f "delims=" %%a in ("%exepath%") do set pathname=%%~nxa
for /f "delims=" %%a in ('dir /s /a /b *.exe') do (
    echo;add firewall input rule, name%pathname%_%%~na
    netsh advfirewall firewall add rule name="%pathname%_%%~na" dir=in program="%%a" action=block
    echo;add firewall output rule, name%pathname%_%%~na
    netsh advfirewall firewall add rule name="%pathname%_%%~na" dir=out program="%%a" action=block
)

echo;
echo;
echo;
echo;success!
pause>nul

