我自己这边加了MySQL、Oracle10G。如果自己相加的话,可以自己照着写一下。
其中用到的语句其实蛮简单的。这里就只写几个比较关键的。
net start 服务名 开启某服务
net stop 服务名 关闭某服务
注:如果服务名有空格,则用双引号括起来。另外服务名不是服务显示的名称,你要右键服务属性才能看到服务名。有时候显示的名称就是服务名。
sc config 服务名 start= 属性(demand 手动、auto 自动、disable 禁用) 设置该服务的启动形式
代码如下:
@echo off
title 各种服务开启、关闭程序
:allstart
cls
echo 吴帅华
echo 1.MySQL 服务开启、关闭
echo 2.Oracle 10G 服务开启、关闭
echo e.退出
set in=
set /p in=请输入:
if "%in%"=="1" goto mysql
if "%in%"=="2" goto oracle10
if "%in%"=="e" goto allclose
rem MySQL服务开启、关闭
:mysql
echo 1.开启mysql服务,2.关闭mysql服务。3.设置为手动。
echo u.回到上层。e.退出。
set in=
set /p in=请输入:
if "%in%"=="1" goto mysqlstart
if "%in%"=="2" goto mysqlstop
if "%in%"=="3" goto mysqlsd
if "%in%"=="u" goto allstart
if "%in%"=="e" goto allclose
:mysqlstart
echo "正在启动MySQL相关开机服务..."
net start MySQL
echo 服务启动完毕!
goto mysql
:mysqlstop
echo "正在关闭MySQL相关开机服务..."
net stop MySQL
echo 服务已关闭!
goto mysql
:mysqlsd
echo "切换MySQL开机启动服务为手动中,请稍候..."
sc config MySQL start= demand
echo 成功切换为手动模式!
goto mysql
rem Oracle XE 服务开启、关闭
:oracle10
echo 1.开启oracle10必要服务,2.关闭oracle10必要服务。3.设置为手动。
echo u.回到上层。e.退出。
set in=
set /p in=请输入:
if "%in%"=="1" goto oracle10start
if "%in%"=="2" goto oracle10stop
if "%in%"=="3" goto oracle10sd
if "%in%"=="u" goto allstart
if "%in%"=="e" goto allclose
:oracle10start
echo "正在启动 oracle10G 必要服务..."
net start OracleOraDb10g_home1TNSListener
net start OracleServiceORCL
echo 服务启动完毕!
goto oracle10
:oracle10stop
echo "正在关闭 oracle10G 相关开机服务..."
net stop OracleOraDb10g_home1TNSListener
net stop OracleServiceORCL
echo 服务已关闭!
goto oracle10
:oracle10sd
echo "切换 oracle10G 开机启动服务为手动中,请稍候..."
sc config OracleOraDb10g_home1TNSListener start= demand
sc config OracleServiceORCL start= demand
echo 成功切换为手动模式!
goto oracle10
echo 按任意键退出
pause
exit