Blocking Folder in Windows Firewall


Blocking All .exe Files in a Folder (Firewall)

Let’s assume that you want to cut internet connection for a specific software, but that software might use another “.exe” files to get connection. So, in order to cut internet connection of that software, you can choose to block internet connection of all “.exe” files in that software setup directory. Unfortunately, there is no option like add folder to firewall. Because of that, we are going to use a simple code to automate that process.

add folder to firewall
@ setlocal enableextensions 
@ cd /d "%~dp0"

for /R %%f in (*.exe) do (
  netsh advfirewall firewall add rule name="Blocked: %%f" dir=out program="%%f" action=block
  1. Copy the given code, paste it to text file and save. Or you can just click here and continue with step 3 with the downloaded file.
  2. Change the file format of saved text file as .bat (if you can’t see the file formats, change folder view settings and disable “hide file formats” option)
  3. Copy this file to the directory of the software that you want to block internet connection.
  4. Run file as administrator.
  5. Congrats, you’ve done it. If you want to check it you can see it on advanced setting of windows defender firewall.