@echo off
REM ============================================================
REM  KIOSK CBT - OTOMATIS (REKOMENDASI)
REM  Windows 7 / 10 / 11 - Edge dulu, kalau tidak ada pakai Chrome
REM  Buka http://192.168.100.14 fullscreen mode kiosk
REM  Taruh file ini di shell:startup
REM  Keluar kiosk: Alt+F4
REM ============================================================
setlocal
set "URL=http://192.168.100.14"

REM --- Tunggu server CBT nyala (maks ~60 detik) ---
set /a TRY=0
:CEK_SERVER
ping -n 1 -w 1000 192.168.100.14 | find "TTL=" >nul
if not errorlevel 1 goto SERVER_OK
set /a TRY+=1
if %TRY% GEQ 20 goto SERVER_OK
timeout /t 3 /nobreak >nul
goto CEK_SERVER
:SERVER_OK

REM --- Matikan browser lama supaya kiosk bersih ---
taskkill /F /IM msedge.exe >nul 2>&1
taskkill /F /IM chrome.exe >nul 2>&1
taskkill /F /IM iexplore.exe >nul 2>&1
timeout /t 2 /nobreak >nul

REM --- 1. Edge Chromium (bawaan Win 10/11, paling disarankan) ---
if exist "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" (
  start "" "%ProgramFiles(x86)%\Microsoft\Edge\Application\msedge.exe" --kiosk %URL% --edge-kiosk-type=fullscreen --inprivate --disable-save-password-bubble --no-first-run --noerrdialogs
  exit /b
)
if exist "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" (
  start "" "%ProgramFiles%\Microsoft\Edge\Application\msedge.exe" --kiosk %URL% --edge-kiosk-type=fullscreen --inprivate --disable-save-password-bubble --no-first-run --noerrdialogs
  exit /b
)

REM --- 2. Chrome (Program Files) ---
if exist "%ProgramFiles%\Google\Chrome\Application\chrome.exe" (
  start "" "%ProgramFiles%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)
if exist "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" (
  start "" "%ProgramFiles(x86)%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)

REM --- 3. Chrome instalasi per-user (sering di Win 7) ---
if exist "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" (
  start "" "%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe" --kiosk %URL% --incognito --disable-save-password-bubble --no-first-run --disable-translate --noerrdialogs
  exit /b
)

REM --- 4. Internet Explorer fallback (Win 7, terakhir) ---
if exist "%ProgramFiles%\Internet Explorer\iexplore.exe" (
  start "" "%ProgramFiles%\Internet Explorer\iexplore.exe" -k %URL%
  exit /b
)
if exist "%ProgramFiles(x86)%\Internet Explorer\iexplore.exe" (
  start "" "%ProgramFiles(x86)%\Internet Explorer\iexplore.exe" -k %URL%
  exit /b
)

echo Browser Edge / Chrome / IE tidak ditemukan di PC ini.
echo Install Edge atau Chrome dulu, lalu jalankan lagi file ini.
pause
exit /b 1
