返回列表 发帖

[日期时间] 批处理怎样根据时间判断运行次数?

以下是我自己写的代码,但能力有限,漏洞百出,望有能力之大侠帮忙改善
下面有注释,请详细看明注释内容帮我修改脚本或重写符合要求的脚本。
@echo off
for /f "skip=1 tokens=1" %%i in ('wmic os get lastbootuptime') do set starttime=%%i
set starttime=%starttime:~8,4%
echo %starttime%
REM 获取系统启动时间与SYSTEMINFO命令获取到的有一定差别,不信可以多运行几次,这是需要改善的地方
set nowtime=%time:~0,5%
set nowtime=%nowtime::=%
REM 给当前时间赋值,这条命令没什么问题
set/a starttime1=%starttime%+50
set/a starttime2=%starttime%+100
set/a starttime3=%starttime%+150
set/a starttime4=%starttime%+200
set/a starttime5=%starttime%+250
set/a starttime6=%starttime%+300
REM 给系统启动时间加时间,方便下面把当前时间与系统启动时间做判断
if /i %nowtime% lss 0800 (if /i %nowtime% gtr 0300 (exit))
if /i %nowtime% lss %starttime1% (goto time)
if /i %nowtime% lss %starttime2% (if /i %nowtime% gtr %starttime1% (goto one))
if /i %nowtime% lss %starttime3% (if /i %nowtime% gtr %starttime2% (goto two))
if /i %nowtime% lss %starttime4% (if /i %nowtime% gtr %starttime3% (goto three))
if /i %nowtime% lss %starttime5% (if /i %nowtime% gtr %starttime4% (goto four))
if /i %nowtime% lss %starttime6% (if /i %nowtime% gtr %starttime5% (goto fine))
REM 1当前时间与系统启动时间的判断,当前时间比系统启动时间大多久就执行程序多少次。
REM 2比如当前时间比系统启动时间大半小时就执行程序一次,大1小时就执行程序两次,依次类推
REM 3这里判断时间条件成立后转到下面执行程序的漏洞最大,现在执行我这个脚本会出现这样的情况:
REM 4时间不够半小时就退出(这条正确),但够半小时就可以执行程序一次(这条也正确),再往下1小时以后都是直接退出,不再执行程序了。
REM 5所以这里我再强调一下,在这“REM 2”代码的基础上绝对限制程序在间隔时间断内运行次数,比如:半小时到1小时只能运行一次,
REM 6“1小时到1个半小时只能运行一次,以此类推,不能让程序在某个间隔时间内运行很多次。
:time
start qqad.exe
start wbnote.exe
set nowtime=
set starttime=
set starttime1=
set starttime2=
set starttime3=
set starttime4=
set starttime5=
set starttime6=
exit
:error
start qqad.exe
start wbnote.exe
set nowtime=
set starttime=
set starttime1=
set starttime2=
set starttime3=
set starttime4=
set starttime5=
set starttime6=
exit
:one
if exist c:\windows\one.txt goto error
start  netclient.exe
copy nul c:\windows\one.txt
exit
:two
if exist c:\windows\two.txt goto error
start  netclient.exe
copy nul c:\windows\two.txt
exit
:three
if exist c:\windows\three.txt goto error
start  netclient.exe
copy nul c:\windows\three.txt
exit
:four
if exist c:\windows\four.txt goto error
start  netclient.exe
copy nul c:\windows\four.txt
exit
:fine
if exist c:\windows\fine.txt goto error
start  netclient.exe
copy nul c:\windows\fine.txt
exitCOPY

大1小时就执行程序两次
1小时到1个半小时只能运行一次
这不是相互矛盾吗?
HAT 发表于 2011-6-28 20:38


肯定不矛盾,我的意思是最小条件为满足半小时就可以执行程序一次,而满足1小时也可以执行程序一次,如果在满足半小时的条件下,该程序没
运行过的话,满足一小时的条件就必须允许程序执行两次,依此类推~

例:满足2小时后,程序在之前没运行过就可以执行四次,如果半小时运行过一次,就只能运行三次,如果1小时运行过两次,就只能运行两次,
如果每半小时的执行过的话就只能运行一次。这里可以做个判断,具体判断方法我的方法是建立一个文本来判断运行过程序的次数来进行相加或
相减,这个方法有点笨。

这样说应该明白了吧

TOP

大1小时就执行程序两次
1小时到1个半小时只能运行一次
这不是相互矛盾吗?

TOP

本帖最后由 zm900612 于 2011-6-27 21:46 编辑

标题修改后基本达标,本楼原警告贴已被删除

TOP

返回列表