打印本页〗〖打印选项
批处理(.bat)定时计划程序
==========ETIME========
@echo off
color 1f
echo.
echo                  定时计划工具 VER:1.0
echo                   by:风弛网络,jastyg
echo               Email:support@efengchi.com
echo                 [url]HTTP://WWW.EFENGCHI.COM[/url]
echo                     for xp/2k3
echo.
echo.

rem ++++++++++++++++++++外部命令行模式的处理+++++++++++++++++++++++++++

rem ===================检测外部是否输入为空后者是帮助信息============
if "%1!%"=="!" goto guihelp                  :如果外部为空,则使用图形页面
if "%1%"=="/?" goto help                     :外部输入/?则出现DOS的帮助提示
if "%1%"=="/h" goto help                     :同上,输入/h
if "%1%"=="/H" goto help                     :同上,分别给出了大小写。
for %%i in (0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31) do if "%1"=="%%i" goto kaishi
goto warng2
rem====================开始对外部输入进行设置和检验==================
:kaishi
if "%1"=="0" set d=0&set riqi=0& goto t      :初始如果日期为0
set /a tmp=%date:~8,3%+0 >nul                :判断日期是否为8号或者9号,以接下文(解决8,9的无效字符方法)
cls                                          :清屏
if errorlevel 9167 goto tmp1                 :接上文接受是否为8号或者9号
goto tmp2

rem====================对8,9号的日期进行确定========================
:tmp1
echo %date:~8,2% >tem.txt                    :导出当前的日期到临时文件
find "08" tem.txt  >nul                      :从临时文件寻找是否含有数值08,以接下文
if not errorlevel 1 set riqi=8&goto tmp3     :判断如果含有08,则设置riqi变量为8,跳转到TMP3标签
find "09" tem.txt  >nul                      :从临时文件寻找是否含有数值09,以接下文
if not errorlevel 1 set riqi=9&goto tmp3     :判断如果含有09,则设置riqi变量为9,跳转到TMP3标签

rem====================对外部日期不为0,8,9的情况下的处理===============
:tmp2
set /a riqi=%date:~8,2%+0                    :对日期进行十位为空去0处理
:tmp3
set /a d=%1+0                                :对用户输入的日期十位为空去0处理

rem===================对外部时间,用户命令进行处理=================================
:t
if exist tem.txt del tem.txt                 :对日期设置完成所留下的临时文件的清理
set t=%2                                     :定义变量T为用户输入的时间
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,) do if "%t:~0,2%"=="%%i" goto CRC
goto warng2
:CRC
if "%t:~2,1%"==":" goto CRC1
goto warng2
:crc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto bcmd
goto warng2

:bcmd
set cmd=%~3                                   :定义运行的程序为用户输入
if "%~3!"=="!" goto command                  :如果用户不输入,则跳到默认设置给的值,到COMMAND
goto 4

:command
set cmd=c:\windows\风弛备份.bat              :设置默认运行命令

rem===================设置外部循环选项命令==========================================
:4
if "%4!%"=="!" goto 41                      :判断是否为空并相对跳转
if "%4%"=="n" goto 41                       :判断是否为小写n并相对跳转
if "%4%"=="N" goto 41                       :是否为大写N并相对跳转
if "%4%"=="y" goto 42                       :是否为小写y并相对跳转
if "%4%"=="Y" goto 42                       :是否为大写Y并相对跳转

rem===================设置默认及不循环==============================================
:41
set rem=echo.                               :定义变量为echo.
goto start                                  :跳转到日期时间的检验部分

:42                
set rem=goto start                          :定义变量为goto 语句,实现循环
set yanchi=ping -n 60 127.1^>nul            :为防止时间在指定时间内多次运行,设置了延迟1分钟
goto start                                  :跳转到日期时间的检验部分
echo.

rem ++++++++++++++++++++图形化的设置和配置处理++++++++++++++++++++++++++++++++++++++++
rem===================图形化帮助提示================================================
:guihelp
echo 请等待......
ping -n 1 ping 127.1 >nul
cls
echo  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo  +用法1:直接运行此文件,跟向导走。需要帮助请输入?或者h                        +
echo  +日期格式:例如9号,可以输入9或者09                                            +
echo  +时间格式采用24小时制,即:20:50 (精度到分钟)                                  +
echo  +用法2:命令行模式;                                                          +
echo  +语法:etime 日 时间 命令(最好写完整路径) Y/N(是否循环运行,默认为N)        +
echo  +例:etime 7 20:20 notepad.exe (7日,20:20运行 NOTEPAD这个程序,并且不循环) +
echo  +例:etime 0 20:20 notepad.exe Y (20:20运行 NOTEPAD这个程序,并且循环)      +
echo  +DOS下输入 etime /? 或者 etime /h 得到帮助                                    +
echo  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

rem===================对用户输入日期进行检测和定义==================================
:begin
echo  请输入日期
set d1=enter                                     :定义一个值给D1,用来下文的用户输入为空的检测
set /p d1=                                       :用户自定义输入
if "%d1%"=="?" goto guihelp                      :图形帮助的调用
if "%d1%"=="h" goto guihelp                      :同上
if "%d1%"=="H" goto guihelp                      :同上
if "%d1%"=="enter" goto warng                    :检测用户输入是否为空,并进行相对处理             
if "%d1%"=="0" set d=0&set riqi=0& goto shij     :检测用户输入是否为0,并相对定义
for %%i in(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,?,h,H,) do if "%
d1%"=="%%i" goto 89
goto warng
:89
set /a tmp=%date:~8,3%+0 >nul                    :判断日期是否为8号或者9号,以接下文(解决8,9的无效字符方法)
cls
if errorlevel 9167 goto tem1                     :接上文接受是否为8号或者9号,并相关跳转
goto tem2

rem====================对8,9号的日期进行确定,同上TMP1========================
:tem1
echo %date:~8,2% >tem.txt
find "08" tem.txt  >nul
if not errorlevel 1 set riqi=8&goto tem3
find "09" tem.txt  >nul
if not errorlevel 1 set riqi=9&goto tem3

rem====================对日期不为0,8,9的情况下的处理,同上TMP2===============
:tem2
set /a riqi=%date:~8,2%+0

:tem3
set /a d=%d1%+0

rem===================对时间,用户命令进行处理=================================
:shij
if exist tem.txt del tem.txt                      :对日期设置完成所留下的临时文件的清理
cls
echo  请输入时间
set t=enter                                       :定义一个值给T,用来下文的用户输入为空的检测
set /p t=                                         :用户自定义输入
if "%t%"=="?" goto guihelp                        :图形帮助的调用
if "%t%"=="h" goto guihelp                        :同上                  
if "%t%"=="H" goto guihelp                        :同上
if "%t%"=="enter" goto warng1                     :检测用户输入是否为空,并进行相对处理
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,?,h,H) do if "%t:~0,2%"=="%%i" goto TCRC
goto warng1
:TCRC
if "%t:~2,1%"==":" goto TCRC1
goto warng1
:tcrc1
for %%i in
(0,1,2,3,4,5,6,7,8,9,01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,
17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,
40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,) do if
"%t:~3,2%"=="%%i" goto cmd
goto warng1

rem==================对用户命令的处理===========================================
:cmd
echo 请输入要执行文件的路径和文件名
set cmd=enter
set /p cmd=
if "%cmd%"=="?" goto guihelp
if "%cmd%"=="h" goto guihelp
if "%cmd%"=="H" goto guihelp
if "%cmd%"=="enter" goto command1                   
goto xunhuan

:command1
set cmd=c:\windows\风弛备份.bat

rem==================定义是否循环================================================
:xunhuan
echo 是否要循环运行? Y/N
set rem=enter
set /p rem=
if "%rem%"=="y" goto 14
if "%rem%"=="Y" goto 14
if "%rem%"=="enter" goto 24
if "%rem%"=="n" goto 24
if "%rem%"=="N" goto 24

:14
set rem=goto start
set yanchi=ping -n 60 127.1^>nul
goto start

:24
set rem=rem goto
cls

rem==================当前日期时间和用户输入日期时间的检测和相对处理========================
:start
if "%riqi%%time:~0,5%"=="%d% %t%" goto run
ping -n 15 127.1>nul

rem==================DOS下的帮助提示=======================================================
:help
chcp 936 >nul
echo 语法:etime 日 时间 命令(最好写完整路径) Y/N(是否循环运行,默认为N)
echo 例:etime 7 20:20 notepad.exe (7日,20:20运行 NOTEPAD这个程序,并且不循环)
echo 例:etime 7 20:20 "del c:\aaa.txt" (指定时间删除特定文件)
echo 例:etime 0 20:20 notepad.exe Y (20:20运行 NOTEPAD这个程序,并且循环)
echo DOS下输入 etime /? 或者 etime /h 得到帮助
goto exit

rem==================输入错误提示==========================================================
:warng
echo 您的日期输入有误!
echo.
goto begin


rem==================输入错误提示==========================================================
:warng1
echo 您的时间输入有误!
echo.
goto shij

rem==================执行用户定义命令或默认命令,以及是否循环==============================
:run
cls
start %cmd%                   :执行命令
%yanchi%                      :延迟时间接上文防止命令多次运行
%rem%                         :定义是否循环
exit                          :程序结束

rem==================退出到提示符下=========================================================
:warng2
echo 语法错误!!
:exit



文章作者:未知