根据选择启动/关闭oracle服务
@echo off
:menu
echo ***************************************************
echo 1 - 启动FS服务11 - 关闭FS服务
echo 2 - 启动GZ服务22 - 关闭GZ服务
echo 3 - 启动ORCL服务33 - 关闭ORCL服务
echo 其他任意键退出
echo ***************************************************
set /p var="请选择你需要的操作:"
goto label%var%
REM START =======================================================
:alreadyStart
@echo 该服务已启动
@pause...
cls
goto :menu
:alreadyStop
@echo 该服务已停止
@pause...
cls
goto :menu
:label1
REM 通过sc query查看服务是否存在,>nul 2>nul表示不管命令是否正确运行,都不会在屏幕看到这个命令所产生的屏幕显示
sc query |find /i "OracleServiceFS" >nul 2>nul
REM echo %errorlevel%,结果如果为0,说明已经启动
if %errorlevel% equ 0 (goto alreadyStart) else (
@echo 正在启动FS服务...
@net start OracleOraDb10g_home1TNSListener
@net start OracleOraDb10g_home1iSQL*Plus
@net start OracleServiceFS
)
@pause...
cls
goto :menu
:label2
sc query |find /i "OracleServiceGZ" >nul 2>nul
if %errorlevel% equ 0 (goto alreadyStart) else (
@echo 正在启动GZ服务...
@net start OracleOraDb10g_home1TNSListener
@net start OracleOraDb10g_home1iSQL*Plus
@net start OracleServiceGZ
)
@pause...
cls
goto :menu
:label3
sc query |find /i "OracleServiceORCL" >nul 2>nul
if %errorlevel% equ 0 (goto alreadyStart) else (
@echo 正在启动ORCL服务...
@net start OracleOraDb10g_home1TNSListener
@net start OracleOraDb10g_home1iSQL*Plus
@net start OracleServiceORCL
)
@pause...
cls
goto :menu
REM STOP =======================================================
:label11
sc query |find /i "OracleServiceFS" >nul 2>nul
REM echo %errorlevel%,结果如果不为0(服务不存在的话,结果为1),说明没启动(已停止)
if not %errorlevel% equ 0 (goto alreadyStop) else (
@echo 正在停止FS服务...
@net stop OracleOraDb10g_home1TNSListener
@net stop OracleOraDb10g_home1iSQL*Plus
@net stop OracleServiceFS
)
@pause...
cls
goto :menu
:label22
sc query |find /i "OracleServiceGZ" >nul 2>nul
if not %errorlevel% equ 0 (goto alreadyStop) else (
@echo 正在停止GZ服务...
@net stop OracleOraDb10g_home1TNSListener
@net stop OracleOraDb10g_home1iSQL*Plus
@net stop OracleServiceGZ
)
@pause...
cls
goto :menu
:label33
sc query |find /i "OracleServiceORCL" >nul 2>nul
if not %errorlevel% equ 0 (goto alreadyStop) else (
@echo 正在停止ORCL服务...
@net stop OracleOraDb10g_home1TNSListener
@net stop OracleOraDb10g_home1iSQL*Plus
@net stop OracleServiceORCL
)
@pause...
cls
goto :menu
参考文章:
IF-ERRORLEVEL使用方法: http://www.jb51.net/article/7525.htm
>nul 2>nul 说明: http://www.jb51.net/article/30536.htm