@echo off
setlocal
cd /d "%~dp0"
set "PS1=%~dp0attyzen-wsl.ps1"
if not exist "%PS1%" (
  echo Dang tai attyzen-wsl.ps1 tu meshchat.attyzen.com...
  powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "try { Invoke-WebRequest -Uri 'https://meshchat.attyzen.com/desk/attyzen-wsl.ps1' -OutFile '%PS1%' -UseBasicParsing } catch { Write-Host 'Khong tai duoc script. Kiem tra mang.'; exit 1 }"
  if errorlevel 1 (
    pause
    exit /b 1
  )
)

net session >nul 2>&1
if %errorLevel% equ 0 goto :elevated

powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath 'powershell.exe' -Verb RunAs -ArgumentList @('-NoProfile','-ExecutionPolicy','Bypass','-File','\"\"%~dp0attyzen-wsl.ps1\"\"')"
exit /b

:elevated
powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%PS1%" %*
if errorlevel 1 pause
exit /b %errorlevel%