Skip to content

Instantly share code, notes, and snippets.

@skkut
Last active November 23, 2025 15:26
Show Gist options
  • Select an option

  • Save skkut/11c68d47af09f2dca717bed5269eb517 to your computer and use it in GitHub Desktop.

Select an option

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

@deividAlfa
Copy link

This modification is 2x faster, as it doesn't wait for the incoming block to finish, also the reduced echo messages help a bit.

@echo off
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 (
		start /min "" netsh advfirewall firewall add rule name="Blocked %%~nxa (Incoming)" dir=in program="%%a" action=block 
		netsh advfirewall firewall add rule name="Blocked %%~nxa (Outgoing)" dir=out program="%%a" action=block 		>nul
		echo Blocked: %%a
    )
)
echo Done!
pause

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