Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
little_bunny pe Simpatie.ro
Femeie
24 ani
Galati
cauta Barbat
27 - 55 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [WINDOWS] Block Any Exe File in Windows Firewall with BAT script Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
Mrrrr
AdMiN

Inregistrat: acum 18 ani
Postari: 2334
The following script runs as admin by default but will require UAC confirmation if UAC is enabled.
It will ask you for a path to the executable file you want blocked in Windows Firewall, pasted into the cmd window and confirmed with Enter key.
Then it will create one inbound and one outbound rule blocking the executable file.
The name of the rule will be the name of the executable file (without .exe) and the words " In" or " Out" depending on the rule.


@echo off
prompt $
setlocal

echo.
echo ==================================================
echo.
echo  This batch script will:
echo.
echo   - Get administrator privileges
echo   - Ask you for an executable file path
echo   - Create INBOUND and OUTBOUND firewall rules
echo   - Block all network connections for that file
echo.
echo ==================================================
echo.
echo "Do you want to continue? [Y/N]"

choice /C YN /N

if errorlevel 2 (
    echo.
    echo Operation cancelled by user.
    timeout /t 2 >nul
    exit /b
)

@echo off
setlocal EnableExtensions EnableDelayedExpansion

:: ===============================
:: Self-elevation check
:: ===============================
net session >nul 2>&1
if %errorlevel% neq 0 (
    powershell -Command "Start-Process '%~f0' -Verb RunAs"
    exit /b
)

:: ===============================
:: Ask for EXE path
:: ===============================
echo.
set /p EXE_PATH=Enter full path to EXE (no need to add quotes):
if not exist "%EXE_PATH%" (
    echo.
    echo ERROR: File not found.
    pause
    exit /b
)

:: ===============================
:: Extract EXE name (without .exe)
:: ===============================
for %%F in ("%EXE_PATH%") do set APP_NAME=%%~nF

set RULE_OUT=%APP_NAME% Out
set RULE_IN=%APP_NAME% In

:: ===============================
:: Remove existing rules (optional)
:: ===============================
netsh advfirewall firewall delete rule name="%RULE_OUT%" >nul 2>&1
netsh advfirewall firewall delete rule name="%RULE_IN%" >nul 2>&1

:: ===============================
:: Create firewall rules
:: ===============================
netsh advfirewall firewall add rule name="%RULE_OUT%" ^
    dir=out program="%EXE_PATH%" action=block profile=any

netsh advfirewall firewall add rule name="%RULE_IN%" ^
    dir=in program="%EXE_PATH%" action=block profile=any

echo.
echo Firewall rules created:
echo   %RULE_OUT%
echo   %RULE_IN%
echo.
pause


Source: ChatGPT


_______________________________________


pus acum 2 saptamani
   
Pagini: 1  

Mergi la