Kae Travis

Alternatives to using WScript.Sleep in a Custom Action

Description:

Sometimes in our Custom Actions we need to pause the script execution, for example when we’re manipulating processes. Since we can’t use Wscript.Sleep from a Custom Action we need another way of pausing the execution of a script. Here I present two alternatives to using WScript.Sleep in a Custom Action.

Source:

NA

Script 1:

Msgbox "start" 
sleep1 5 
MsgBox "stop" 

Sub sleep1(strSeconds) 
       	Dim dteWait : dteWait = DateAdd("s", strSeconds, Now()) 
       	Do Until (Now() > dteWait) 
       	Loop 
End Sub

Script 2:

Msgbox "start"
sleep2 5
MsgBox "stop"

Sub sleep2(strSeconds)    
       	Dim objShell : set objShell = CreateObject("wscript.Shell")
    	objShell.Run "%COMSPEC% /c ping -n " & strSeconds & " 127.0.0.1>nul",0,1 
	set objShell = Nothing
End Sub
Alternatives to using WScript.Sleep in a Custom Action
Alternatives to using WScript.Sleep in a Custom Action

3 thoughts on “Alternatives to using WScript.Sleep in a Custom Action

  1. i want to run a script whole day. it ll do some works on some particular time only. (e-x) executing a batch file at 6:00pm. if i use “wscript.sleep 10000” then its giving some outof memory errror. how can i avoid that.?

  2. Hi.  Remember that these scripts were intended for Custom Actions.  Also it depends how you’ve authored your scripts and your loops.  Please post your script over at ITNinja (or in some other forum) and I’m sure somebody will point you in the right direction!

Leave a Reply to Kae Cancel reply