RSS

HTA Scripting: sleep function

02 Jan

Okay, for all the HTA newbies, the sleep function much be one of the most searched piece of code (the other is how to write a console-like output). Having been a full-fledged vbscript scripter, we don’t think much about the wscript.sleep method until we try to use it on a HTA script.. it does not work!

The Microsoft Scripting center’s solution for this either to use the DHTML method setTimeOut. I don’t really like the solution because it doesn’t really “sleep” the application. Rather, it sets a time delay before the application runs. The sample application is too simplistic. It calls a stub which creates a timer to launch the application at the specified delay time and passes control back to the form.

But what if I have a process that needs to pause a few seconds before it continues? I don’t think that the setTimeOut method can address this well enough.

There are others out there that recommends 3rd party addon, but wanted a more native solution.

After searching for a while, I chanced upon this little workaround in Rube Goldberg Memorial Scripting Page. Its not sometime I really like because it depends on the ping command, but it presents a better workaround than the setTimeout method for what I want to do.

Msgbox now

ccSleep 15
MsgBox now

Sub ccSleep(seconds)
set oShell = CreateObject(“Wscript.Shell”)
cmd = “%COMSPEC% /c ping -n ” & 1 + seconds & ” 127.0.0.1>nul”
oShell.Run cmd,0,1
End Sub

Advertisements
 
Leave a comment

Posted by on January 2, 2008 in Scripts, VBScripts, Windows

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: