(Solved) How to block multiple EXE files in windows firewall

(Solved) How to block multiple EXE files Windows Firewall.


Block entire folders .exe in Windows Firewall Solved.



batch


It is very simple to block all .exe file from folder and sub-folder in windows firewall using batch file.
.
To do so, you will copy code and paste in notepad and save as .bat file and run it as administrator. It's ask for confirmation press yes to continue.



Note: - Run this file under which folder you want to block.

----------------------------------------Code Start from Here ------------------------------------
@echo off
title: Block entire folders and subfolders .exe
cls
net session >nul 2>&1
    if %errorLevel% == 0 (
        echo.
    ) else (
        GOTO :NOPERM
    )
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
  set "DEL=%%a"
)
@cd /d "%~dp0"
for %%* in (.) do set RULENAME=%%~nx*
ECHO|set /p =" Add "
call :ColorText 0a "Block In & Out "
ECHO  Firewall rules for all *.exe files
ECHO.
ECHO|set /p = " located at '"
  call :ColorText 0b "%CD%'"
call :ColorText 0a "Including subfolders"
ECHO.
ECHO|set /p = " creating "
  call :ColorText 1b "%RULENAME%"
ECHO  as the Firewall rule name ?
ECHO.
ECHO.
ECHO.
ECHO Press any key to continue  or  CTRL+C to terminate now ...
pause >nul
cls
Echo.
FOR /r %%G in ("*.exe") Do (@echo %%G
NETSH advfirewall firewall add rule name="%%G" dir=in program="%%G" action="block" enable="yes")
FOR /r %%G in ("*.exe") Do (@echo %%G
NETSH advfirewall firewall add rule name="%%G" dir=out program="%%G" action="block" enable="yes")
Echo.
  call :ColorText 0a "done"
ECHO|set /p =" ... Goodbye"
ECHO.
ECHO.
ECHO Press a key to exit ...
pause >nul
goto :eof

:ColorText
echo off
"%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
goto :eof

:Finish
Echo.
Echo.
Echo Batch ended...
Goto :END

:NOPERM
ECHO.
ECHO   You must run this file in Administrator mode
ECHO.
ECHO.
ECHO.
ECHO|SET /p =" Press any key to exit ..."
Pause >NUL
ECHO   goodbye
ECHO.
ECHO.
:END

----------------------------------------Code End Here ------------------------------------


SHARE

Ibrar Ansari

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment