wnmp启停脚本

windows下启动mysql、php、nginx

::关闭回显
@echo off

set WNMP_HOME=C:/wnmp
set NGINX_HOME=C:/wnmp/nginx-1.14.0
set PHP_HOME=C:/wnmp/php-7.2.7-nts-Win32-VC15-x64

echo Starting mysql...
set status=1
(tasklist|find /I "mysqld.exe" || set status=0) 2>nul 1>nul
if %status% equ 1 (
    echo mysqld.exe already exists
) else (
    ::net start 命令必须用管理员权限才能运行
    net start mysql
)

::输出换行
echo.

echo Starting php-cgi...
set status=1
(tasklist|find /I "php-cgi.exe" || set status=0) 2>nul 1>nul
if %status% equ 1 (
    echo php-cgi.exe already exists
) else (
    %WNMP_HOME%/RunHiddenConsole.exe %PHP_HOME%/php-cgi.exe -b 127.0.0.1:9000 -c %PHP_HOME%/php.ini
    echo php-cgi.exe start!
)

::输出换行
echo.

echo Starting nginx...
set status=1
(tasklist|find /I "nginx.exe" || set status=0) 2>nul 1>nul
if %status% equ 1 (
    echo nginx.exe already exists
) else (
    %WNMP_HOME%/RunHiddenConsole.exe %NGINX_HOME%/nginx.exe -p %NGINX_HOME%
    echo nginx.exe start!
)

::输出换行
echo.
pause

关闭nginx、php、mysql

::关闭回显
@echo off

echo Stopping nginx...
taskkill /F /IM nginx.exe > nul

echo.

echo Stopping php-cgi...
taskkill /F /IM php-cgi.exe > nul

echo.

echo Stopping mysql...
net stop mysql

echo.
pause

由于需要用到管理员权限运行,但原bat脚本无法设置每次默认用管理员权限运行, 只能点每次点右键进行管理员运行,这很蛋疼。

有个曲线救国的方法。把bat脚本放到其他目录下,然后发送快捷方式到桌面,右键快捷方式点击“属性”—“快捷方式”选项卡—“高级”—“用管理员身份运行”勾选上即可。

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top