@echo off
title Block in Firewall
set ver=v3

fltmc >nul 2>&1 || (
  echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\GetAdmin.vbs"
  echo UAC.ShellExecute "%~fs0", "", "", "runas", 1 >> "%temp%\GetAdmin.vbs"
  cmd /u /c type "%temp%\GetAdmin.vbs">"%temp%\GetAdminUnicode.vbs"
  cscript //nologo "%temp%\GetAdminUnicode.vbs"
  del /f /q "%temp%\GetAdmin.vbs" >nul 2>&1
  del /f /q "%temp%\GetAdminUnicode.vbs" >nul 2>&1
  exit
)


set "programPath1=C:\program files\hasleo\easyuefi\bin\easyuefi.exe"
set "programPath2=C:\Program Files\Hasleo\EasyUEFI\bin\WINPE\Program Files\EasyUEFI\bin\easyuefi.exe"
set "name1=easyuefi"
set "name2=easyuefi"

call :CheckAndAddToFirewall "%programPath1%" "%name1%"
call :CheckAndAddToFirewall "%programPath2%" "%name2%"

echo.

@pause
exit /b

:CheckAndAddToFirewall
setlocal
set "ruleExists=0"

reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\SharedAccess\Parameters\FirewallPolicy\FirewallRules" /s | findstr /C:"%~1" >nul

if not errorlevel 1 (
    set "ruleExists=1"
)

if "%ruleExists%"=="1" (
    echo - The program has already been blocked in the Windows Firewall.
	echo.
) else (
    netsh advfirewall firewall add rule name="%~2" dir=out program="%~1" action=block
    if %errorlevel% equ 0 (
        echo Successfully blocked the program "%~2" in the Windows Firewall.
    )
)
endlocal
exit /b
