我尝试运行一个VBScript来检查时间,直到它到达22:00 (10‘m),然后运行shutdown.bat。我总是收到这样的错误:“没有‘do’的‘loop’”。有没有人可以看一下我的代码,看看有没有办法修复它?
Do
If Hour(Time()) => 22 And Minute(Time()) => 30 And Hour(Time()) < 23 Then
Loop Until True
Then
'Dim shell
Set shell = CreateObject("WScript.Shell")
shell.Run "shutdown.bat"
Set shell = Nothing
End If发布于 2017-01-29 08:32:15
如果你真的想让一个循环一直运行到某个特定的小时,下面是它的实现方法:
Do While True ' = Do the following forever (or until something breaks the loop)
If Hour(Time()) => 22 And Minute(Time()) => 30 And Hour(Time()) < 23 Then
' Do whatever you want and then
' break the loop:
Exit Do
End If
Loop但是,我不建议这样做,因为它将消耗大量资源。相反,您应该使用Task Scheduler。
希望这能有所帮助:)
发布于 2017-01-29 11:14:58
循环直到当前时间大于所需的结束时间:
endtime = CDate("22:30")
Do Until Time > endtime
WScript.Sleep 100
Loop
CreateObject("WScript.Shell").Run "shutdown.bat"在循环中使用WScript.Sleep可以确保循环不会耗尽CPU。
但是,正如@AhmedAbdelhameed已经提到的,创建在所需时间运行shutdown.bat的计划任务通常效率要高得多。
https://stackoverflow.com/questions/41916291
复制相似问题