[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[日期时间] 批处理怎么判断每次程序运行的时间?

1. 首先用systeminfo或其它方法获取计算机开机时间

2. 判断当前时间是否比计算机时间大于2小时,或4小时,或6小时,或8小时,或..... , 就运行程序
但是最重要的要求是,比如在大于2小时的基础上
已经运行过这个脚本了就必须得等当前时间大于4小时以上才能运行本程序,依次类推

“当前时间比计算机时间大于”3小时,或者大于2小时零几分(不能规定死了)并且这个脚本在2小时到4小时的时间段
没有运行过就可以运行程序。  
当前时间比计算机开机时间大于4小时小于6小时的时候运行过这个脚本
就给出提示“必须再次等到2小时之后才能运行本程序”,依次类推


罗嗦一下:“当前时间比计算机时间大于”这条我再详细说明一下:当前时间比计算机时间大于4小时(4-6小时的任何时间段内),并且这个脚本在4小时到6小时的时间段"没有运行过" 就可以运行程序。 依次类推


解释:“依次类推”的意思是说,这里打个比方 1+2+3+4+5+...+100 ,不可能把1+2+3一直加到100都写完,这样的话看起来太罗嗦了!

请不要滥用字体和颜色设置,这很影响他人阅读和版面的整洁

别的没看懂...先给出获取开机/登录时间的代码吧
  1. net user %username%|find "上次登录"
  2. ::获取登录时间
  3. wmic os get lastbootuptime
  4. ::获取开机时间,也可以:
  5. systeminfo|find "系统启动时间"
  6. ::这个比较慢,建议还是用wmic来获取
复制代码

TOP

我自己写了个,不过执行效率相当的低,而且双重判断还会出错,批处理不可能双重判断吗?
@echo off
if exist cjl.txt goto start
for /f "tokens=1,2,3" %%i in ('systeminfo^|find "系统启动时间:"') do set starttime=%%k
set starttime=%starttime:~0,5%
set starttime=%starttime::=%
set nowtime=%time:~0,5%
set nowtime=%nowtime::=%
set/a starttime1=%starttime%+200
set/a starttime2=%starttime%+400
set/a starttime3=%starttime%+600
set/a starttime4=%starttime%+800
set/a starttime5=%starttime%+1000
echo 系统启动时间:  %starttime%
echo 当前时间:        %nowtime%
echo 系统启动时间+2小时:        %starttime1%
echo 系统启动时间+4小时:        %starttime2%
echo 系统启动时间+6小时:        %starttime3%
echo 系统启动时间+8小时:        %starttime4%
echo 系统启动时间+10小时:      %starttime5%
copy nul cjl.txt
::pause&exit
if %nowtime% lss %starttime5%(if %nowtime% gtr %starttime4% goto four)
if %nowtime% lss %starttime4%(if %nowtime% gtr %starttime3% goto three)
if %nowtime% lss %starttime3%(if %nowtime% gtr %starttime2% goto twp)
if %nowtime% lss %starttime2%(if %nowtime% gtr %starttime1%) goto one
if %nowtime% lss %starttime1% goto time




pause
:time
mshta vbscript:createobject("wscript.shell").popup("上机不足两小时,每两小时可以抽奖一次",3,"警告",32)(window.close)
exit

:error
mshta vbscript:createobject("wscript.shell").popup("每两小时只能抽奖一次",3,"警告",32)(window.close)
exit


ne
if exist one.txt goto error
start  netclient.exe
copy nul one.txt
exit

:two
if exist two.txt goto error
start  netclient.exe
copy nul two.txt
exit

:three
if exist three.txt goto error
start  netclient.exe
copy nul three.txt
exit

:four
if exist four.txt goto error
start  netclient.exe
copy nul four.txt
exit

:fine
if exist fine.txt goto error
start  netclient.exe
copy nul fine.txt
exit

TOP

返回列表