Skip to content

Instantly share code, notes, and snippets.

@Mosdatlan-falusi
Created May 8, 2021 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mosdatlan-falusi/c6573d40c0ffe415ac908ac0aa17b155 to your computer and use it in GitHub Desktop.
Save Mosdatlan-falusi/c6573d40c0ffe415ac908ac0aa17b155 to your computer and use it in GitHub Desktop.
Creates a firewall rule for all .exe files in it s folder and in all folders below.
@echo off
@ setlocal enableextensions
@ cd /d "%~dp0"
echo.
echo This script file has to be copied to a folder that
echo contains the files you want to block on Windows Firewall.
echo It will block all .exe files in that folder and subfolders.
echo.
echo RUN IT AS ADMINISTATOR
echo.
echo.
echo -------------------------------------------------
echo Close the script now if it is not located
echo in the desired folder.
echo -------------------------------------------------
echo.
PAUSE
cls
echo.
echo.
for /R %%a in (*.exe) do (
echo ::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::
echo Blocking: %%a
echo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
echo Outbound:
netsh advfirewall firewall add rule name="%%a" dir=out action=block program="%%a"
echo Inbound:
netsh advfirewall firewall add rule name="%%a" dir=in action=block program="%%a"
echo ::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::-::
echo.
)
echo.
echo ::::::::::::::::
echo Done
echo ::::::::::::::::
echo.
echo.
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment