@echo off
setlocal enabledelayedexpansion
:: Configurable Paths
set "GenshinImpactPath=F:\Games\HoYoPlay\games\Genshin Impact game\GenshinImpact.exe"
set "StarRailPath=F:\Games\HoYoPlay\games\Star Rail Games\StarRail.exe"
set "ZenlessZoneZeroPath=F:\Games\HoYoPlay\games\ZenlessZoneZero Game\ZenlessZoneZero.exe"
:: Log File
set "log_file=GameLauncher.log"
echo [%date% %time%] Script started >> "%log_file%"
:: Check if the script is running as an administrator
openfiles >nul 2>&1
if %errorlevel% neq 0 (
echo This script requires administrative privileges.
echo Right-click on the script and select 'Run as administrator'.
echo [%date% %time%] Script exited due to lack of administrative privileges >> "%log_file%"
pause
exit /b
)
:: ASCII Art and Descriptive Headings
echo.
echo ____________________________________________________________________________
echo ^| ^|
echo ^| Game Launcher ^|
echo ^| ^|
echo ^|__________________________________________________________________________^|
echo.
echo.
:menu
cls
echo Select the game to launch:
echo 1. Genshin Impact
echo 2. Star Rail
echo 3. Zenless Zone Zero
echo 4. Exit
set /p choice=Enter your choice [1-4]:
if "%choice%"=="1" goto genshin
if "%choice%"=="2" goto star_rail
if "%choice%"=="3" goto zenless_zone_zero
if "%choice%"=="4" goto end
echo Invalid choice, please try again.
echo [%date% %time%] Invalid choice entered: %choice% >> "%log_file%"
pause
goto menu
:genshin
set "game_name=Genshin Impact"
set "game_path=%GenshinImpactPath%"
goto launch_game
:star_rail
set "game_name=Star Rail"
set "game_path=%StarRailPath%"
goto launch_game
:zenless_zone_zero
set "game_name=Zenless Zone Zero"
set "game_path=%ZenlessZoneZeroPath%"
goto launch_game
:launch_game
if not exist "%game_path%" (
echo Error: The game executable for %game_name% does not exist at %game_path%.
echo [%date% %time%] Error: Game executable for %game_name% does not exist at %game_path% >> "%log_file%"
pause
goto menu
)
echo Launching %game_name%...
start "" "%game_path%"
if %errorlevel% neq 0 (
echo Error: Failed to launch %game_name%.
echo [%date% %time%] Error: Failed to launch %game_name% >> "%log_file%"
pause
goto menu
)
echo Waiting for %game_name% to start...
timeout /t 5 /nobreak >nul
call :monitor_game "%game_name%" "%game_path%"
goto end
:monitor_game
set "game_name=%~1"
set "game_path=%~2"
set "game_exe=%~nx2"
:loop
wmic process where name="%game_exe%" get processid | findstr /r /c:"^[0-9][0-9]*" >nul
if "%errorlevel%"=="0" (
echo Found ZFGameBrowser.exe, terminating...
taskkill /f /im ZFGameBrowser.exe
echo [%date% %time%] Terminated ZFGameBrowser.exe >> "%log_file%"
)
) else (
echo %game_name% has closed.
echo [%date% %time%] %game_name% has closed >> "%log_file%"
goto end
)
timeout /t 5 /nobreak >nul
goto loop