Skip to content

Instantly share code, notes, and snippets.

@otsmr otsmr/firewall.bat
Created Jun 6, 2019

Embed
What would you like to do?
@echo off
@setlocal enableextensions
@setlocal EnableDelayedExpansion
@cd /d "%~dp0"
color 06
title Firewall
set location=%cd%
echo.
echo. ========================================================
echo. Firewall 1.0
echo. ========================================================
echo.
call:checkPerm
echo.
echo. .exe Dateien werden in %location% gesucht.
echo.
echo. Treffer:
echo. ------------------------------------------
FOR /r %%B in (*.exe) do (echo. %%~nxB)
echo. ------------------------------------------
echo.
CHOICE /C jn /M "> Firewall Regeln hinzufuegen"
IF Errorlevel 2 goto EXIT
IF Errorlevel 1 goto ADD
:ADD
echo.
set /p add="> Name der Regel: "
:block
set c=0
echo.
echo. Eingehende Regeln:
echo. ------------------------------------------
FOR /r %%B in (*.exe) do (
set /a c=!c!+1
echo. !c!. '%%~nxB' wird blockiert...
netsh advfirewall firewall add rule name="%add% (%%~nxB)" dir=in action=block program="%%~dpfnxB"
)
echo. ------------------------------------------
echo.
echo. Ausgehende Regeln:
echo. ------------------------------------------
set c=0
FOR /r %%B in (*.exe) do (
set /a c=!c!+1
echo. !c!. '%%~nxB' wird blockiert...
netsh advfirewall firewall add rule name="%add% (%%~nxB)" dir=out action=block program="%%~dpfnxB"
)
echo. ------------------------------------------
echo.
CHOICE /C jn /M "> Windows Firewall oeffnen?
IF Errorlevel 2 goto EXIT
IF Errorlevel 1 goto OPEN
:OPEN
start "C:\Windows\System32" rundll32.exe shell32.dll,Control_RunDLL firewall.cpl
Goto EXIT
:checkPerm
net session >nul 2>&1
if %errorLevel% == 0 (
echo. Permissions: OK
) else (
color 04
echo. Permissions: FALSE
echo.
echo. Das Programm benoetigt Administratorrechten.
pause>nul
goto exit
)
cd %~dp0
goto:eof
:EXIT
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.