Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
635 views
in Technique[技术] by (71.8m points)

loops - Looping VBScript

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

Hope that helps :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...