vbscript 了解批次是否在过去X小时内执行过

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了vbscript 了解批次是否在过去X小时内执行过相关的知识,希望对你有一定的参考价值。

@echo off

pushd %~dp0
::sync
start /wait "" cmd /c cscript date.vbs
::async - debug
::start /b "" cscript date.vbs

if %errorlevel% EQU 0 (
	echo it's been less than 24 hours
	goto :eof
)

echo it's been more than 24 hours since last execution
::here we would execute the task
'################ name it date.vbs #################
Function Write(data, outFile)
	Set objFSO=CreateObject("Scripting.FileSystemObject")
	Set objFile = objFSO.CreateTextFile(outFile,True)
	objFile.Write data & vbCrLf
	objFile.Close
	
End Function

Function ReadDate()
	Set objFSO=CreateObject("Scripting.FileSystemObject")
	strFile="time.log"
	Set objFile = objFSO.OpenTextFile(strFile)
	Do Until objFile.AtEndOfStream
		strLine= objFile.ReadLine
		'Wscript.Echo strLine
	Loop
	objFile.Close
	ReadDate = strLine
End Function

Function HoursDiff(dt1, dt2) 
        If (isDate(dt1) And IsDate(dt2)) = false Then 
            TimeSpan = "00:00:00" 
            Exit Function 
        End If 

        HoursDiff = Abs(DateDiff("H", dt1, dt2)) 
End Function 

    oldDate = ReadDate() 'last Date
    d2 = Now() 
    
    h = HoursDiff(oldDate, d2) 
   
	Escriu d2, "time_last_try.log" 'we write the last try
  
If h < 24 Then 'change this if you want something
	Wscript.quit(0) 'retruns 0 if it has been executed the last 24 hours
Else
	Wscript.echo "writing new date"
	Write d2, "time.log"
	Wscript.quit(1) 'retruns 1 if it has been more than 24 hours since the last execution
End If

以上是关于vbscript 了解批次是否在过去X小时内执行过的主要内容,如果未能解决你的问题,请参考以下文章

在过去 24 小时内从 MySQL 中选择行并根据间隔 X 跳过行?

在过去 X 小时内从 HBase 表中获取所有数据的最佳方法是啥?

确定字符串“a”在“x”小时内是不是相同然后执行“Y”的 Bash 脚本

从最近 24 小时内上传的文件夹中获取文件

vbscript 批次NCBI

查找过去24小时内已更改或创建的所有文件和文件夹