Files
SeeyonFileSystem/server/ctl.bat
2026-07-18 10:53:23 +08:00

64 lines
1.5 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
title 程序管理脚本
:: ================= 配置区 =================
:: 设置目标exe文件名
set "EXE_NAME=server.exe"
:: 设置exe完整路径 (如果exe和bat在同一目录可使用 %~dp0%EXE_NAME%)
set "EXE_PATH=%~dp0%EXE_NAME%"
:: =========================================
:menu
echo.
echo ================================
echo 程序管理菜单
echo ================================
echo 1. 启动程序
echo 2. 关闭程序
echo 3. 重启程序 (先关后开)
echo 4. 退出
echo ================================
set /p choice="请输入选项 (1-4): "
if "%choice%"=="1" goto start_prog
if "%choice%"=="2" goto stop_prog
if "%choice%"=="3" goto restart_prog
if "%choice%"=="4" exit
echo 无效选项,请重试
goto menu
:start_prog
echo [INFO] 正在检查程序是否已运行...
tasklist /fi "imagename eq %EXE_NAME%" | find /i "%EXE_NAME%" >nul
if %errorlevel% equ 0 (
echo [WARN] 程序 [%EXE_NAME%] 已经在运行中。
) else (
if exist "%EXE_PATH%" (
echo [INFO] 正在启动: %EXE_PATH%
start "" "%EXE_PATH%"
echo [SUCCESS] 程序已启动。
) else (
echo [ERROR] 未找到文件: %EXE_PATH%
)
)
pause
goto menu
:stop_prog
echo [INFO] 正在尝试关闭进程: %EXE_NAME% ...
taskkill /f /im "%EXE_NAME%" >nul 2>&1
if %errorlevel% equ 0 (
echo [SUCCESS] 进程已强制关闭。
) else (
echo [WARN] 未检测到运行中的进程或关闭失败。
)
pause
goto menu
:restart_prog
call :stop_prog
timeout /t 2 /nobreak >nul
call :start_prog
goto menu