win本机设置服务启停脚本 将以下内容放到新建的.bat文件脚本示例MySQL服务更换服务中对应的名称即可启停其他服务例如Redis服务等echo off chcp 65001 nul setlocal EnableExtensions rem 到服务中找mysql对应名称复制需要区分大小写 set SVCMySQL rem 无管理员权限时弹出 UAC提权后重新运行本脚本 net session nul 21 if errorlevel 1 ( powershell -NoProfile -Command Start-Process -FilePath %~f0 -Verb RunAs exit /b ) echo. echo MySQL 服务开关 echo 服务名: %SVC% echo. set RUNNING0 for /f tokens* %%A in (sc query %SVC% 2^nul ^| findstr /I RUNNING) do set RUNNING1 if %RUNNING%1 ( echo 当前状态: 运行中 echo 正在关闭 MySQL ... net stop %SVC% if errorlevel 1 (echo [失败] 停止服务失败) else (echo [成功] MySQL 已停止) ) else ( echo 当前状态: 已停止 ^(或未运行^) echo 正在启动 MySQL ... net start %SVC% if errorlevel 1 ( echo [失败] 启动服务失败 echo 可尝试: net start %SVC% ) else ( echo [成功] MySQL 已启动 ) ) echo. sc query %SVC% | findstr /I SERVICE_NAME STATE echo. endlocal exit /b