bat wnmp

@echo off
rem 提供Windows下nginx的啟動,重啟,關(guān)閉功能
 
echo ==================begin========================
 
cls 
::ngxin 所在的盤符
set NGINX_PATH=F:
 
::nginx mysql 所在目錄
set NGINX_DIR=F:\xampp\nginx\
set MYSQL_DIR=F:\xampp\mysql\bin\
color 0a 
TITLE 拉風的老衲
 
CLS 
 
echo 初始化... 

GOTO restart  
:MENU 
 
::tasklist|findstr /i "nginx.exe"
::tasklist /fi "imagename eq nginx.exe"
::*************************************************************************************************************
echo. 
    echo.  [1] 啟動wnmp  
    echo.  [2] 關(guān)閉wnmp 
    echo.  [3] 重啟wnmp 
    echo.  [0] 退 出 
echo. 
 
echo.請輸入選擇的序號:
set /p ID=
    IF "%id%"=="1" GOTO start 
    IF "%id%"=="2" GOTO stop 
    IF "%id%"=="3" GOTO restart 
    IF "%id%"=="0" EXIT
PAUSE 
 
::*************************************************************************************************************
::啟動
:start 
    call :startNginx
    call :startMysql
    GOTO MENU
 
::停止
:stop 
    call :shutdownNginx
    call :shutdownMysql
    GOTO MENU
 
::重啟
:restart 
    call :shutdownNginx
    call :startNginx
    call :shutdownMysql
    call :startMysql
    GOTO MENU
    
::*************************************************************************************
::底層
::*************************************************************************************
:shutdownNginx
    taskkill /F /IM nginx.exe > nul
    echo nginx shut success
    goto :eof
 
:startNginx
    IF NOT EXIST "%NGINX_DIR%nginx.exe" (
        goto :eof
     )
 
    %NGINX_PATH% 
    cd "%NGINX_DIR%" 
 
    IF EXIST "%NGINX_DIR%nginx.exe" (
        start "" nginx.exe
    )
    echo nginx start success
    goto :eof
:startMysql
    net start "MySQL"
    echo mysql start success
    goto :eof
:shutdownMysql
    sc query |find /i "MySQL" >nul 2>nul
    if not errorlevel 1 (net stop "MySQL")
    echo mysql shutdown success
    goto :eof
  

net start "MySQL" 如果執(zhí)行失敗 服務(wù)名無效,因為net start +服務(wù)名,啟動的是win下注冊的服務(wù)。此時,系統(tǒng)中并沒有注冊mysql到服務(wù)中。即下面沒有mysql服務(wù)
1.進入MySQL的bin目錄
2.在命令行窗口輸入:mysqld –install,回車,提示:Service successfully installed,代表注冊服務(wù)成功。
3.測試結(jié)果 net start mysql

補充
如果要刪除服務(wù):
sc delete ServiceName
停止服務(wù)
net stop mysql
查看更多操作
sc –help

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容