标题: [日期时间] 批处理定时工具 [打印本页]
作者: cjiabing 时间: 2010-6-28 23:40 标题: 批处理定时工具
可以用来设定定时关机、定时重启、定时打开新程序、定时关闭新程序等等定时任务。使用定时功能需先开启Task Scheduler服务,适用于XP系统。打开新程序只需输入程序的路径和执行时间,而关闭程序是以结束该程序进程来做到的。好像只执行当天的时间任务,不能执行非当天的任务
-
- @echo off
- ::by cjiabing &from http://hi.baidu.com/cjiabing
- :start
- MODE con: COLS=48 LINES=19
- COLOR 3E
- cls
- call :dt
- echo ╭═════════╮
- echo ║ 甲兵时代 ║
- echo ╭═════┤ 定时任务工具 ├═════╮
- echo ║ ║ V2.2 ║ ║
- echo ║ ╰═════════╯ ║
- echo ║ 1、定时关机 ║
- echo ║ 2、取消定时关机 ║
- echo ║ 3、定时打开程序 ║
- echo ║ 4、定时关闭程序 ║
- echo ║ 5、查看、删除计划任务 ║
- echo ║ 6、开启任务计划服务功能 ║
- echo ║ 7、其它计划功能 ║
- echo ║ 8、语音时钟与明星报时 ║
- echo ║ 9、CMD ║
- echo ║ 0、退出 ║
- echo ╰═════════════════════╯
- echo.
- set /p xze= 请选择任务:
- if %xze%==1 goto task1
- if %xze%==2 goto task3
- if %xze%==3 goto task4
- if %xze%==4 goto task5
- if %xze%==5 goto task6
- if %xze%==6 goto task7
- if %xze%==7 goto task77
- if %xze%==8 call :task82
- if %xze%==9 goto task9
- if %xze%==0 exit
- goto start
- :dt
- title Date:%date%;Time:%time:~0,5%
- goto :eof
- :task1
- cls
- call :dt
- echo.
- echo.
- echo 定时关机
- echo.
- echo.
- echo 时间格式:13:26 23:46 00:16 0:36 2:06
- echo.
- set /p tasktime= 执行时间(返回B;重启C):
- if /i %tasktime%==c goto task2
- if /i %tasktime%==b (goto start) else (echo.)
- at %tasktime% shutdown -s -f -t 60
- echo.
- echo 任务开始,正在返回!
- ping /n 3 127.0.1>nul
- goto start
-
- :task2
- cls
- call :dt
- echo.
- echo.
- echo 定时重启
- echo.
- echo.
- echo 时间格式:13:26 23:46 00:16 0:36 2:06
- echo.
- set /p tasktime= 执行时间(返回B):
- if /i %tasktime%==b (goto start) else (echo.)
- at %tasktime% shutdown -r -f -t 60
- echo.
- echo 任务开始,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task3
- cls
- echo.
- echo.
- echo 取消定时关机和重启
- echo.
- echo.
- shutdown -a
- echo.
- echo 取消完成,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task4
- ::使用at打开的程序会自动隐藏?
- cls
- echo.
- echo.
- echo 定时执行程序
- echo.
- echo.
- echo.
- echo 路径含有空格时需外加双引号
- ::echo 运行程序以隐藏窗口形式运行
- ::echo 查看关闭程序请重新运行程序
- echo 获取桌面快捷方式指向路径:P
- echo 返回:B
- echo.
- echo.
- call :dt
- set /p pat= 程序路径:
- if /i %pat%==b (goto start) else (echo.)
- if /i %pat%==p (call :task8&cls&goto task4) else (echo.)
- echo.
- echo.
- echo 时间格式:13:26 23:46 00:16 0:36 2:06
- echo.
- call :dt
- set /p tasktime= 执行时间:
- echo.
- echo.
- at %tasktime% /interactive %pat%
- echo.
- echo 任务开始,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- at 13:45 /interactive "D:\Program Files\TTPlayer\TTPlayer.exe"
-
- :task5
- cls
- echo.
- echo.
- echo 定时关闭程序
- echo.
- echo.
- call :dt
- set /p prss= 进程名称(不用.exe;返回B):
- if /i %prss%==b (goto start) else (echo.)
- echo.
- echo.
- echo 时间格式:13:26 23:46 00:16 0:36 2:06
- echo.
- call :dt
- set /p tasktime= 执行时间:
- echo.
- at %tasktime% taskkill /f /t /im %prss%.exe
- ::at 00:03 taskkill /f /t /im TTPlayer.exe
- ::D:\Program Files\TTPlayer\TTPlayer.exe
- echo.
- echo 任务完成,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task6
- MODE con: COLS=90 LINES=30
- COLOR 3E
- cls
- echo.
- echo.
- echo 查看计划任务
- echo.
- at
- echo.
- pause
- echo.
- echo.
- echo 删除计划任务
- echo.
- set /p xzc= 选择删除/全部清除/返回(x/c/b):
- echo.
- if /i %xzc%==b goto start
- if /i %xzc%==x (
- set /p xzdel= 输入需要删除任务的ID?序号?行号?:
- at %xzdel% /Delete
- goto task6
- )
- if /i %xzc%==c at /Delete /yes
- echo.
- echo 任务完成,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task7
- cls
- echo.
- echo.
- echo 开关Task Scheduler服务项
- echo.
- echo.
- echo 使用定时功能需开启Task Scheduler服务
- echo 但该服务项也可能被其它程序和病毒使用
- echo.
- set /p xzef= 开启服务【Y】,关闭服务【N】:
- if /i %xzef%==y goto task71
- if /i %xzef%==n goto task72
- goto start
- :task71
- cls
- echo.
- echo.
- echo 开启Task Scheduler服务
- echo.
- sc config schedule start= auto
- sc start schedule
- ::net start "Task Scheduler"
- echo.
- echo 开启完成,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task72
- cls
- echo.
- echo.
- echo 关闭Task Scheduler服务
- echo.
- sc stop schedule
- ::net stop "Task Scheduler"
- echo.
- echo 关闭完成,正在返回!
- ping /n 3 127.0.1>nul
- goto start
- :task8
- cls
- echo.
- echo.
- echo 获取桌面快捷方式指向的路径
- echo.
- echo 配合定时打开程序使用
- echo 只查找EXE的快捷方式
- echo 支持模糊搜索
- echo.
- echo.
- echo.
- set /p iput= 快捷方式名称(返回B):
- if /i %iput%==b (goto start) else (echo.)
- type "%USERPROFILE%\桌面\*%iput%*.lnk" | find /i "exe" | find /i "\">>_findpath.txt
- echo.
- type "%ALLUSERSPROFILE%\桌面\*%iput%*.lnk" | find /i "exe" | find /i "\">>_findpath.txt
- echo.>>_findpath.txt
- echo.>>_findpath.txt
- for /f "tokens=*" %%a in (_findpath.txt) do echo "%%a">>_findpath.txt
- echo.>>_findpath.txt
- echo 当路径名含有空格时,请使用加双引号的路径>>_findpath.txt
- start _findpath.txt
- echo.
- echo 关闭完成,正在返回!
- ping /n 3 127.0.1>nul
- del /f /q _findpath.txt
- goto :eof
- :task9
- MODE con: COLS=90 LINES=30
- COLOR 3E
- cls
- echo.
- echo CMD环境,使用exit退出!
- echo.
- call :dt
- echo.
- CMD /k cd /d c:\
- ::CMD /k cd /d c:\
- echo.
- pause
- goto start
-
- :task82
- cls
- echo.
- echo.
- echo 语音时钟与明星报时
- echo.
- echo 现在时间是:%time:~0,5%
- echo.
- echo 1、现在报时
- Echo 2、设置每天每小时语音报时
- echo 3、修改语音报时参数
- echo 4、明星报时
- echo 5、设置每天每小时明星报时
- echo 6、修改明星报时参数
- echo 7、查看与清除报时任务
- echo 8、安装、卸载与帮助
- echo 0、返回
- echo.
- C:\Baoshi\_read.vbs 今天是%date:~0,4%年%date:~5,2%月%date:~8,2%日%date:~11,3%
- :task88
- cls
- echo.
- echo.
- echo 语音时钟与明星报时
- echo.
- echo 现在时间是:%time:~0,5%
- echo.
- echo 1、现在报时
- Echo 2、设置每天每小时语音报时
- echo 3、修改语音报时参数
- echo 4、明星报时
- echo 5、设置每天每小时明星报时
- echo 6、修改明星报时参数
- echo 7、查看与清除报时任务
- echo 8、安装、卸载与帮助
- echo 0、返回
- echo.
- set /p xzeb= 请选择:
- taskkill /f /t /im wmplayer.exe>nul 2>nul
- if %xzeb%==1 call :yybs
- if %xzeb%==2 goto baosm
- if %xzeb%==3 goto eyy
- if %xzeb%==4 goto mxbs
- if %xzeb%==5 goto mxbst
- if %xzeb%==6 goto emx
- if %xzeb%==7 goto cbs
- if %xzeb%==8 goto inst
- if %xzeb%==0 goto start
- goto task88
- :yybs
- if not exist c:\Baoshi md c:\Baoshi
- if not exist c:\Baoshi\Baoshi.bat call :baosm2
- start /min "" c:\Baoshi\Baoshi.bat /B
- goto :eof
- :cbs
- MODE con: COLS=85 LINES=25
- schtasks
- echo.
- set /p xzc= 清除/返回(c/b):
- echo.
- if %xzc%==b goto bse
- del c:\Baoshi\_read.vbs>nul 2>nul
- schtasks /delete /tn "Baoshi" /f
- goto bse
- :mxbs
- if not exist c:\Baoshi\Sound cls&echo 没有安装明星报时语音包& ping /n 3 127.0.1>nul&goto task88
- if exist "c:\Baoshi\sound\%time:~0,2%.mp3" (start /min wmplayer.exe c:\Baoshi\sound\%time:~0,2%.mp3) else (start /min wmplayer.exe "c:\Baoshi\sound\0%time:~1,1%.mp3")
- goto task88
-
- :mxbst
- cls
- if not exist c:\Baoshi md c:\Baoshi
- if not exist c:\Baoshi\MXBaoshi.bat call :mxbst2
- sc config schedule start= auto
- sc start schedule
- schtasks /delete /tn "Baoshi" /f>nul 2>nul
- schtasks /create /ru system /sc hourly /st 00:00:00 /ed 2050/07/26 /tn "Baoshi" /tr c:\Baoshi\MXBaoshi.bat
- ping /n 2 127.0.1>nul
- goto bse
- :mxbst2
- echo @echo off>>c:\Baoshi\MXBaoshi.bat
- echo if exist "c:\Baoshi\sound\%%time:~0,2%%.mp3" (start /min wmplayer.exe c:\Baoshi\sound\%%time:~0,2%%.mp3) else (start /min wmplayer.exe "c:\Baoshi\sound\0%%time:~1,1%%.mp3")>>c:\Baoshi\MXBaoshi.bat
- echo ping /n 15 127.0.1^>nul>>c:\Baoshi\MXBaoshi.bat
- echo taskkill /f /t /im wmplayer.exe>>c:\Baoshi\MXBaoshi.bat
- echo exit>>c:\Baoshi\MXBaoshi.bat
- goto :eof
- :baosm
- cls
- if not exist c:\Baoshi md c:\Baoshi
- if not exist c:\Baoshi\MXBaoshi.bat call :baosm2
- sc config schedule start= auto
- sc start schedule
- schtasks /delete /tn "Baoshi" /f>nul 2>nul
- schtasks /create /ru system /sc hourly /st 00:00:00 /ed 2050/07/26 /tn "Baoshi" /tr c:\Baoshi\Baoshi.bat
- ping /n 2 127.0.1>nul
- goto bse
- :baosm2
- copy %~f0 c:\Baoshi
- echo @echo off>c:\Baoshi\Baoshi.bat
- echo ^set vn^=^0>>c:\Baoshi\Baoshi.bat
- echo ^set rn^=^0>>c:\Baoshi\Baoshi.bat
- :baosm3
- echo for /f "tokens=1,2,3 delims=:" %%%%i in ('echo %%time%%') do set tvar=%%%%i点%%%%j分>>c:\Baoshi\Baoshi.bat
- echo echo Set oVoice = CreateObject("SAPI.SpVoice") ^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo with oVoice ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo set .voice = .GetVoices.Item^(%%vn%%^) ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo .Volume = 100 ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo .rate = %%rn%% ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo .speak(Wscript.Arguments(0)) ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo echo end with ^>^>c:\Baoshi\_read.vbs>>c:\Baoshi\Baoshi.bat
- echo c:\Baoshi\_read.vbs "现在时间是%%tvar%%!">>c:\Baoshi\Baoshi.bat
- echo exit>>c:\Baoshi\Baoshi.bat
- goto :eof
- :bse
- MODE con: COLS=48 LINES=19
- echo.
- echo 设置完成,正在返回!
- ping /n 3 127.0.1>nul
- goto task88
- :eyy
- cls
- echo.
- echo.
- echo 修改语音报时参数
- echo.
- echo 现在时间是:%time:~0,5%
- echo.
- echo.
- echo 可系统设置:控制面板→语音→设置
- echo.
- del c:\Baoshi\_read.vbs>nul 2>nul
- set /p vn= 请设定朗读语音(0~3;默认为0):
- set /p rn= 请设定朗读语速(-10~10;默认为0):
- if %rn% equ " " (%rn%=0)
- echo @echo off>c:\Baoshi\Baoshi.bat
- call :baosm3
- goto bse
- :emx
- cls
- echo.
- echo.
- echo 修改明星报时参数
- echo.
- echo 现在时间是:%time:~0,5%
- echo.
- echo.
- set /p bsexe= 设置播放程序(默认wmplayer.exe):
- if exist c:\Baoshi\MXBaoshi.bat del c:\Baoshi\MXBaoshi.bat
- echo @echo off>>c:\Baoshi\MXBaoshi.bat
- echo start /min %%bsexe%% c:\Baoshi\sound\%%time:~0,2%%.mp3>>c:\Baoshi\MXBaoshi.bat
- echo ping /n 15 127.0.1^>nul>>c:\Baoshi\MXBaoshi.bat
- echo taskkill /f /t /im %%bsexe%%>>c:\Baoshi\MXBaoshi.bat
- echo exit>>c:\Baoshi\MXBaoshi.bat
- goto bse
- :inst
- cls
- echo.
- echo.
- echo 安装、卸载与帮助
- echo.
- echo.
- echo.
- echo 1、安装
- echo 2、卸载
- echo 3、帮助
- echo 0、返回
- echo.
- set /p ins= 请选择:
- if %ins%==1 goto inst1
- if %ins%==2 goto unin
- if %ins%==3 goto help1
- if %ins%==0 goto task88
- goto inst
- :inst1
- cls
- echo.
- echo.
- echo 拷贝当前程序至c:\Baoshi
- echo 拷贝明星语音包“Sound”至c:\Baoshi
- if not exist c:\Baoshi\Sound md c:\Baoshi\Sound
- ping /n 2 127.0.1>nul
- echo.
- "%ProgramFiles%\WinRAR\Rar.exe" x Sound.rar c:\Baoshi\Sound
- ping /n 2 127.0.1>nul
- copy %~f0 c:\Baoshi
- copy %~f0 "%USERPROFILE%\桌面"
- xcopy /s Sound c:\Baoshi\Sound
- goto bse
- :unin
- cls
- echo.
- echo.
- echo 清理程序与c:\Baoshi下的明星语音包
- ping /n 2 127.0.1>nul
- echo.
- set /p chd= 一旦卸载你将无法恢复,是否卸载?(Y/N):
- if /i %chd%==Y (goto unin2) else (goto :task88)
- :unin2
- echo.
- del /s /q c:\Baoshi\*.*"
- rd /s /q c:\Baoshi
- schtasks /delete /tn "Baoshi" /f
- goto bse
- :help1
- cls
- echo.
- echo 1)语音报时需安装中文TTS语音插件
- Echo 2)控制面板→语音→设置→选择缺省语音
- Echo 3)明星报时需明星报时语音包“Sound”
- Echo 4)语音名称格式:07.mp3——23.mp3
- echo 5)解压至:c:\Baoshi\Sound
- echo 6)使用Windows Media Player或TTPlayer
- echo 7)需开启Task Scheduler服务
- echo.
- pause
- goto inst
-
复制代码
[ 本帖最后由 cjiabing 于 2010-10-21 23:41 编辑 ]
作者: c64kkd 时间: 2010-11-10 13:10
受益匪浅。好指标!试了可以用,感谢楼主的分享
作者: mstsc 时间: 2011-7-17 19:22
很好很有用,具体的还要慢慢研究
作者: wangxiulin 时间: 2011-7-18 15:25
恩!不错!!!!!!!!!!!!!!!
作者: wangxiulin 时间: 2011-7-18 15:36
批处理学得不错!!!!
作者: 狱渊 时间: 2013-5-1 10:44
很好用 谢了
作者: hnldwhm52 时间: 2014-9-11 12:12
谢谢分享。
作者: Hawk3 时间: 2014-10-23 22:51
谢谢楼主,受用了
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |