How can I pause an execution of a script from within? Something like Sleep WinAPI function?
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.
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.
Quitting a vbscript application would simply be a Wscript. Quit - so that part doesn't really apply.
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.)
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With