beckham79 发表于 2015-4-6 13:01:42

批处理启动和停止VMware、Apache、MySQL、MSSQL、andLinux服务

最近我们正在用Apache + MySQL +PHP + PHPMyAdmin + eclipse +Zend Optimizer+ Dreamweaver 在 Windows 下做一个PHP开发。因为Apache、MySQL、MSSQL、andLinux的服务默认都是随着电脑的启动而启动的,在不用的时候白占资源,所以昨天高手给我一个批处理程序来实现这些服务的启动和关闭。经过琢磨后,因为VMware有4个服务也有同样的情况,所以就将这个功能进行了扩展来实现上述所有服务的启动与关闭。现将源代码公布如下:(写完后保存为.cmd)     @echo off
set split=+-----------------------+
:main
cls
echo What do you want?
echo   %split%
echo   ^|         list:         ^|
echo   %split%
echo   ^| Start Services   ^|
echo   ^| Stop Services    ^|
echo   %split%
echo   ^| EXIT             ^|
echo   %split%
set Choice=
set /P Choice=Your Choice:
echo ----------------------------------
if /I "%Choice%"=="" goto main
if /I "%Choice%"=="1" goto start
if /I "%Choice%"=="2" goto stop
if /I "%Choice%"=="E" goto exit
goto main
:start
cls
echo Which service do you want to start?
echo   %split%
echo   ^|                      list:                  ^|
echo   %split%
echo   ^|    Apache2.2                           ^|
echo   ^|    MySQL                                 ^|
echo   ^|    andLinux                              ^|
echo   ^|    MSSQL                                 ^|
echo   ^|    VMware Authorization Service          ^|
echo   ^|    VMware DHCP Service                   ^|
echo   ^|    VMware Virtual Mount Manager Extended ^|
echo   ^|    VMware NAT Service                  ^|
echo   %split%
echo   ^|    QUIT                                  ^|
echo   %split%
set Choice=
set /P Choice=Your Choice:
echo ----------------------------------
if /I "%Choice%"=="" goto start
if /I "%Choice%"=="1" goto sta1
if /I "%Choice%"=="2" goto sta2
if /I "%Choice%"=="3" goto sta3
if /I "%Choice%"=="4" goto sta4
if /I "%Choice%"=="5" goto sta5
if /I "%Choice%"=="6" goto sta6
if /I "%Choice%"=="7" goto sta7
if /I "%Choice%"=="8" goto sta8
if /I "%Choice%"=="Q" goto main
goto start
:sta1
net start Apache2.2
echo Apache has started.
goto ask
:sta2
net start MySQL
echo MySQL has started.
goto ask
:sta3
net start andLinux
echo andLinux has started.
goto ask
:sta4
net start MSSQLSERVER
echo MSSQLSERVER has started.
goto ask
:sta5
net start "VMware Authorization Service"
echo VMware Authorization Service has started.
goto ask
:sta6
net start "VMware DHCP Service"
echo VMware DHCP Service has started.
goto ask
:sta7
net start "VMware Virtual Mount Manager Extended"
echo VMware Virtual Mount Manager Extended has started.
goto ask
:sta8
net start "VMware NAT Service"
echo VMware NAT Service has started.
goto ask
:stop
cls
echo Which service do you want to stop?
echo   %split%
echo   ^|                      list:                  ^|
echo   %split%
echo   ^|    Apache2.2                           ^|
echo   ^|    MySQL                                 ^|
echo   ^|    andLinux                              ^|
echo   ^|    MSSQL                                 ^|
echo   ^|    VMware Authorization Service          ^|
echo   ^|    VMware DHCP Service                   ^|
echo   ^|    VMware Virtual Mount Manager Extended ^|
echo   ^|    VMware NAT Service                  ^|
echo   %split%
echo   ^|    QUIT                                  ^|
echo   %split%
set Choice=
set /P Choice=Your Choice:
echo ----------------------------------
if /I "%Choice%"=="" goto stop
if /I "%Choice%"=="1" goto sto1
if /I "%Choice%"=="2" goto sto2
if /I "%Choice%"=="3" goto sto3
if /I "%Choice%"=="4" goto sto4
if /I "%Choice%"=="5" goto sto5
if /I "%Choice%"=="6" goto sto6
if /I "%Choice%"=="7" goto sto7
if /I "%Choice%"=="8" goto sto8
if /I "%Choice%"=="Q" goto main
goto stop
:sto1
net stop Apache2.2
echo Apache has stoped.
goto ask
:sto2
net stop MySQL
echo MySQL has stoped.
goto ask
:sto3
net stop andLinux
echo andLinux has stoped.
:sto4
net stop MSSQLSERVER
echo MSSQLSERVER has stoped.
goto ask
:sto5
net stop "VMware Authorization Service"
echo VMware Authorization Service has stoped.
goto ask
:sto6
net stop "VMware DHCP Service"
echo VMware DHCP Service has stoped.
goto ask
:sto7
net stop "VMware Virtual Mount Manager Extended"
echo VMware Virtual Mount Manager Extended has stoped.
goto ask
:sto8
net stop "VMware NAT Service"
echo VMware NAT Service has stoped.
goto ask
:ask
echo ----------------------------------
set Choice=
set /P Choice=Start Others?(y/n)
if "%Choice%"=="y" goto main
:exit
exit
页: [1]
查看完整版本: 批处理启动和停止VMware、Apache、MySQL、MSSQL、andLinux服务