REM 將引號內部分改爲你要查找的服務名稱 sc query |find /i "mysql" >nul 2>nul REM 若是服務存在,跳轉至exist標籤 if not errorlevel 1 (goto exist) else goto notexist REM 服務存在時啓用mysql服務 :exist echo 服務存在 goto :eof REM 服務不存在時安裝mysql服務 :notexist echo 服務不存 goto :eof