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.
@ 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 ) pause
- 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.
- 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)
- Copy this file to the directory of the software that you want to block internet connection.
- Run file as administrator.
- Congrats, you’ve done it. If you want to check it you can see it on advanced setting of windows defender firewall.