Skip to content

Instantly share code, notes, and snippets.

@sean1832
Created November 5, 2025 09:54
Show Gist options
  • Select an option

  • Save sean1832/0b7c82a66609ef1e66ef474051a91242 to your computer and use it in GitHub Desktop.

Select an option

Save sean1832/0b7c82a66609ef1e66ef474051a91242 to your computer and use it in GitHub Desktop.
Automatically add all .exe file to firewall rule
@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