@echo off

rem Check if XAMPP control panel is already running
tasklist /fi "imagename eq xampp-control.exe" 2>NUL | find /I /N "xampp-control.exe">NUL
if "%ERRORLEVEL%"=="0" (
    echo XAMPP control panel is already running
    rem Stop the running XAMPP control panel
    TASKKILL /F /IM xampp-control.exe
) else (
    echo XAMPP control panel is not running
)

rem Check if Apache is already running
netstat -ano | find ":80" > nul
if not errorlevel 1 (
    echo Apache is already running, Stopping the process
    TASKKILL /F /IM apache.exe
) else (
    echo Apache is not running
)

rem Check if MySQL is already running
netstat -ano | find ":3306" > nul
if not errorlevel 1 (
    echo MySQL is already running, Stopping the process
    TASKKILL /F /IM mysqld.exe
) else (
    echo MySQL is not running
)

if "%OS%" == "Windows_NT" goto WinNT

:Win9X
echo Don't be stupid! Win9x don't know Services
echo Please use apache_start.bat instead
goto exit

:WinNT
echo Installing Apache2.4 as an Service
c:\xampp\apache\bin\httpd -k install
echo Now we Start Apache2.4 :)
net start Apache2.4
echo =====================================
timeout /t 3 /nobreak > nul

echo Installing MySQL as an Service
c:\xampp\mysql\bin\mysqld --install
echo Now we Start MySQL :)
net start mysql
echo =====================================

timeout /t 3 /nobreak > nul

rem Start the XAMPP control panel in silent mode
start "" "C:\xampp\xampp-control.exe"

rem Open the project URL in the browser
start "" "https://mm88.mgk.com"

rem Add a delay of 3 seconds to allow Apache to start
timeout /T 3


rem Close the command prompt window
start /B exit