@echo off
setlocal

set "TARGET_PATH=%~1"
if "%TARGET_PATH%"=="" set "TARGET_PATH=%~dp0jx2anhem"

net session >nul 2>&1
if errorlevel 1 (
  powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -ArgumentList '\"%TARGET_PATH%\"' -Verb RunAs"
  exit /b
)

powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$path = [System.IO.Path]::GetFullPath('%TARGET_PATH%');" ^
  "try {" ^
  "  Add-MpPreference -ExclusionPath $path -ErrorAction Stop;" ^
  "  Write-Host ('Added Windows Defender exclusion: ' + $path);" ^
  "} catch {" ^
  "  Write-Host $_.Exception.Message;" ^
  "  exit 1;" ^
  "}"

exit /b %errorlevel%
