Skip to content

Instantly share code, notes, and snippets.

@skkut
Last active April 29, 2025 06:58
Show Gist options
  • Save skkut/11c68d47af09f2dca717bed5269eb517 to your computer and use it in GitHub Desktop.
Save skkut/11c68d47af09f2dca717bed5269eb517 to your computer and use it in GitHub Desktop.
A windows batch file to block all applications in a folder in Windows firewall
@ setlocal enableextensions
@ cd /d "%~dp0"
for /R %%a in (*.exe) do (
netsh advfirewall firewall add rule name="Blocked with Batchfile %%a" dir=out program="%%a" action=block
)
@c0r37py
Copy link

c0r37py commented Apr 13, 2025

this is what you need.

@echo off
setlocal enableextensions
cd /d "%~dp0"

set extensions=.exe .dll .com .bat .cmd .ps1 .vbs .js .py

for %%e in (%extensions%) do (
    for /R %%a in (*%%e) do (
        echo Found: %%a
        call netsh advfirewall firewall add rule name="Blocked %%~nxa (Incoming)" dir=in program="%%a" action=block
        call netsh advfirewall firewall add rule name="Blocked %%~nxa (Outgoing)" dir=out program="%%a" action=block
        echo Blocked: %%a
    )
)

echo Done!
endlocal
pause

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment