Skip to content

Instantly share code, notes, and snippets.

@AdamQuixote
Last active March 4, 2020 11:30
Show Gist options
  • Save AdamQuixote/9774751 to your computer and use it in GitHub Desktop.
Save AdamQuixote/9774751 to your computer and use it in GitHub Desktop.
I found this script on a web forum, when I was looking for an easy way to add every executable in a folder to a firewall rule. This is tested for Windows 7 and Windows 8, and running the script inside a folder will automatically block outgoing Internet access for every program inside the folder. The script creates a separate rule for every progr…
@echo off
REM BATCH FILE CREATED BY CHARLES DE HAVILLAND 20/02/2012
cls
If "%1"=="" GOTO :norulename
SET RULENAME=%1
ECHO Create in/out firewall rules for all *.exe files with the rulename of "%RULENAME%" ?
ECHO.
pause
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.
Echo done.
Echo.
GOTO :Finish
:norulename
Echo Error! - You did not specify a Rulename, which is needed to define your rules. example: "C:\> addfwrs.bat myrule"
Echo.
pause
:Finish
Echo Batch ended...
@AdKiller
Copy link

Thank you very much for sharing.
I am astonished that Microsoft does not add a quick and simple way to block programs with Windows Firewall.

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