Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pause a vbscript execution?

Tags:

vbscript

How can I pause an execution of a script from within? Something like Sleep WinAPI function?

like image 260
Andrej Kirejeŭ Avatar asked Oct 27 '10 20:10

Andrej Kirejeŭ


People also ask

How do I add a pause in VBScript?

Script snip below creates a pause sub that displayes the pause text in a string and waits for the Enter key. z can be anything. Great if multilple user intervention required pauses are needed. I just keep it in my standard script template.

How do I stop a VBScript execution?

Start Task Manager, click on the Processes tab, right-click on wscript.exe and select End Process, and confirm in the dialog that follows. This will terminate the wscript.exe that is executing your script.

How do I close an application in VBScript?

Quitting a vbscript application would simply be a Wscript. Quit - so that part doesn't really apply.

What does WScript sleep do?

A script can force itself to pause by calling the WScript Sleep method. The Sleep method accepts a single parameter that indicates how long, in milliseconds, to pause the script. (There are 1,000 milliseconds in a second and 60,000 milliseconds in a minute.)


1 Answers

You can use a WScript object and call the Sleep method on it:

Set WScript = CreateObject("WScript.Shell")
WScript.Sleep 2000 'Sleeps for 2 seconds

Another option is to import and use the WinAPI function directly (only works in VBA, thanks @Helen):

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sleep 2000
like image 166
Oded Avatar answered Oct 04 '22 02:10

Oded