Google Reviews
If you find this content or our services useful, please leave us a review.


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.



Script 1:

Msgbox "start" 
sleep1 5 
MsgBox "stop" 

Sub sleep1(strSeconds) 
       	Dim dteWait : dteWait = DateAdd("s", strSeconds, Now()) 
       	Do Until (Now() > dteWait) 
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 & ">nul",0,1 
	set objShell = Nothing
End Sub
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!

Comments have now been disabled. If you have a question to ask about this post please ask the community!