@echo off chcp 65001 >nul setlocal set "PROJECT_DIR=%~dp0" set "RUN_DIR=%PROJECT_DIR%.run" set "PID_FILE=%RUN_DIR%\spine-particle-windows.pid" cd /d "%PROJECT_DIR%" if not exist "%PID_FILE%" ( echo 没有发现由“启动项目-Windows.bat”启动的项目进程。 exit /b 0 ) set /p SERVER_PID=<"%PID_FILE%" powershell -NoProfile -Command ^ "$process=Get-CimInstance Win32_Process -Filter ('ProcessId = ' + $env:SERVER_PID) -ErrorAction SilentlyContinue;" ^ "if ($null -eq $process) { exit 2 };" ^ "$expected=(Join-Path $env:PROJECT_DIR 'node_modules\vite\bin\vite.js');" ^ "if ($process.CommandLine -notlike ('*' + $expected + '*')) { exit 3 };" ^ "Stop-Process -Id ([int]$env:SERVER_PID) -Force; exit 0" set "STOP_RESULT=%ERRORLEVEL%" if "%STOP_RESULT%"=="3" ( echo PID 已被其他程序占用,为避免误关进程,本次未执行停止操作。 del /q "%PID_FILE%" >nul 2>&1 pause exit /b 1 ) del /q "%PID_FILE%" >nul 2>&1 if "%STOP_RESULT%"=="2" ( echo 项目已经停止。 ) else if "%STOP_RESULT%"=="0" ( echo 项目已停止。 ) else ( echo 停止项目失败,请检查 PowerShell 权限。 pause exit /b 1 ) exit /b 0