Alternatives to using WScript.Sleep in a Custom Action


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