循环 VBScript [英] Looping VBScript

查看:22
本文介绍了循环 VBScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行 VBScript 检查时间,直到它到达 22:00(晚上 10 点),然后运行 ​​shutdown.bat.我总是收到诸如没有‘做’的‘循环’"之类的错误.谁能看看我的代码,看看是否有办法修复它?

I'm trying to run a VBScript checking the time until it reaches 22:00 (10PM), and then runs shutdown.bat. I always get errors such as "'loop' without 'do'". Can anyone look at my code and see if there's a way to fix it?

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

推荐答案

如果您真的想保持循环运行直到到达特定时间,请按以下方式完成:

If you really want to keep a loop running until it reaches a specific hour, here's how it's done:

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调度器.

However, I wouldn't recommend that because it will consume much resources. Instead, you should be using Task Scheduler.

希望有帮助:)

这篇关于循环 VBScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆