0% found this document useful (0 votes)
42 views2 pages

Blocking Communication - Bat

This batch script is designed to create firewall rules that block incoming and outgoing traffic for all executable files in a specified directory and its subfolders. It checks for administrative permissions before proceeding and prompts the user for confirmation before executing the firewall commands. The script also includes functions for colored text output and handles cases where the script is not run with the required permissions.

Uploaded by

yupjop999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views2 pages

Blocking Communication - Bat

This batch script is designed to create firewall rules that block incoming and outgoing traffic for all executable files in a specified directory and its subfolders. It checks for administrative permissions before proceeding and prompts the user for confirmation before executing the firewall commands. The script also includes functions for colored text output and handles cases where the script is not run with the required permissions.

Uploaded by

yupjop999
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

@echo off

cls
net session >nul 2>&1
if %errorLevel% == 0 (
echo.
) else (
GOTO :NOPERM
)
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do
rem"') do (
set "DEL=%%a"
)
@cd /d "%~dp0"
for %%* in (.) do set RULENAME=%%~nx*
ECHO|set /p ="- Add "
call :ColorText 0a "Block In & Out "
ECHO Firewall rules for *.exe
ECHO.
ECHO|set /p = "- at folder '"
call :ColorText 0b "%CD%'"
ECHO (includes subfolders)
ECHO.
ECHO|set /p = "- Create "
call :ColorText 1b "%RULENAME%"
ECHO as Firewall name?
ECHO.
ECHO.
ECHO.
ECHO Press any key to continue or CTRL+C to exit the application ...
pause >nul
cls
Echo.
FOR /r %%G in ("*.exe") Do (@echo %%G
NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=in program="%%G"
action="block" enable="yes")
FOR /r %%G in ("*.exe") Do (@echo %%G
NETSH advfirewall firewall add rule name="%RULENAME%-%%~nxG" dir=out program="%%G"
action="block" enable="yes")
Echo.
call :ColorText 0a "DONE"
ECHO.
ECHO.
ECHO Press any key to continue to exit the application ...
pause >nul
goto :eof

:ColorText
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

:Finish
Echo.
Echo.
Echo Prikaz dokoncen...
Goto :END

:NOPERM
ECHO.
ECHO - The program must be run as an administrator!
ECHO.
ECHO.
ECHO.
ECHO|SET /p ="- Press any key to continue to exit the application ..."
Pause >NUL
ECHO goodbye
ECHO.
ECHO.
:END

You might also like