Created
November 5, 2025 09:54
-
-
Save sean1832/0b7c82a66609ef1e66ef474051a91242 to your computer and use it in GitHub Desktop.
Automatically add all .exe file to firewall rule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @echo off | |
| :: -- Self-elevation check -- | |
| NET SESSION >nul 2>&1 | |
| if %ERRORLEVEL% NEQ 0 ( | |
| echo Requesting administrative privileges... | |
| powershell -Command "Start-Process -FilePath '%~f0' -Verb runAs" | |
| exit /B | |
| ) | |
| :: -- Elevated -- | |
| pushd "%~dp0" | |
| echo Blocking all .exe in and out through Windows Firewall under "%CD%"... | |
| for /R %%f in (*.exe) do ( | |
| echo Blocking "%%~f"... | |
| netsh advfirewall firewall add rule ^ | |
| name="Blocked: %%~f" ^ | |
| dir=out ^ | |
| program="%%~f" ^ | |
| action=block ^ | |
| enable=yes >nul | |
| netsh advfirewall firewall add rule ^ | |
| name="Blocked: %%~f" ^ | |
| dir=in ^ | |
| program="%%~f" ^ | |
| action=block ^ | |
| enable=yes >nul | |
| ) | |
| echo. | |
| echo Done. Press any key to exit. | |
| pause >nul | |
| popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment