标题: [文本处理] 求批处理在指定时间执行某命令 [打印本页]
作者: winsfly 时间: 2012-10-11 09:03 标题: 求批处理在指定时间执行某命令
本帖最后由 winsfly 于 2012-10-11 09:24 编辑
电脑的计划任务关闭,不能运行at命令,想用if /I %time% GEQ xx:xx:xx.00 但是行不通,原因是比如我想在8点到18点正执行某命令,那么8居然大于等于10~18,
@echo off
if /I %time% GEQ 18:00:00.00 (start "" "http://x.3318.cc/"&exit) else (goto a)
:a
echo.
echo.
echo.
echo.
echo.
echo 本网站属于非商业盈利性质,
echo 下午18点过后将停止服务!!!
echo.
echo.
echo.
echo.
echo.
ping 127.0.0.1 -n 10 >nul
exit
这个批处理执行结果是 凌晨2-9点 18-23点 都会显示停止服务!但是我要的是8点到17:59:59.59都能打开网站
还有一个问题就是如果用echo %time% >time.txt
if /f "tokens=1 delims=:" %%i in (time.txt) do xxxxxxxx命令的话会提示此时不应有i% 好像此xpsp3系统不能用if /f命令提取
作者: 51894660 时间: 2012-10-11 12:48
本帖最后由 51894660 于 2012-10-11 13:18 编辑
这是可以显示当前时间的 如果不想要 可以按根据第二行合适修改 这样代码就会少很多
下面问题代码有错误吧 是for 不是if
我试了你说的代码 可以提取- @ECHO OFF
- echo %time% >time.txt
- for /f "tokens=1 delims=:" %%i in (time.txt) do echo %%i
- pause
复制代码
一直开着 根据设定的时间会自动开启或关闭服务
XPSP3环境下测试成功通过 win7的童鞋注意 win7防火墙服务名为MpsSvc 自己修改后在测试- @echo off
- ::参照这里
- ::========================================================================
- if %time:~0,2% geq 18 (net stop sharedaccess) else (if %time:~0,2% lss 8 (net stop sharedaccess) else (net start sharedaccess&&goto str2))
- ::========================================================================
- :str
- echo %time:~0,8%
- ping -n 2 127.0.0.1>nul
- cls
- if %time:~0,2% equ 8 (net start sharedaccess) else goto :str
-
- :str2
- echo %time:~0,8%
- ping -n 2 127.0.0.1>nul
- cls
- if %time:~0,2% geq 18 (net stop sharedaccess) else goto :str2
- goto str
复制代码
作者: wc726842270 时间: 2012-10-11 15:29
SCHTASKS
看好了,帮助还是很大的
作者: winsfly 时间: 2012-10-11 15:46
回复 2# 51894660
不错,本人一直对批处理情有独钟,就是学得慢
作者: 51894660 时间: 2012-10-11 17:03
回复 4# winsfly
我也是才学的 简单的会 看到复杂的 经常死一片脑细胞
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |