Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WScript.Sleep for HTA?

1,203 views
Skip to first unread message

McKirahan

unread,
Apr 14, 2005, 9:37:45 AM4/14/05
to
I've got an HTA that does a bunch of database processing
during which I update a <textarea> with progress messages.

Timestamped messages are added at the top if the
<textarea> (so they don't scroll out of site).

It appears that it isn't updated when the Sub is called.

Is there an equivalent to one of the following that I could use?
WScript.Sleep (WSH), Response.Flush (ASP), DoEvents (VB).

Basically, I use:

Call doStatus("Progress.")

Sub doStatus(what)
document.formHTA.Status.value = Now & what & vbCrLf & _
document.formHTA.Status.value
End Sub

<form name="formHTA">
<textarea name="Status" cols="50" rows="8" readonly></textarea>
</form>

Thanks in advance.


[ I posted this yesterday with the (incomplete!) Subject of "HTA"
in the microsoft.public.inetserver.asp.components newsgroup. ]


Joe Fawcett

unread,
Apr 14, 2005, 11:33:01 AM4/14/05
to
"McKirahan" <Ne...@McKirahan.com> wrote in message
news:woCdndg_x7W...@comcast.com...

> I've got an HTA that does a bunch of database processing
> during which I update a <textarea> with progress messages.
>
> Timestamped messages are added at the top if the
> <textarea> (so they don't scroll out of site).
>
> It appears that it isn't updated when the Sub is called.
>
> Is there an equivalent to one of the following that I could use?
> WScript.Sleep (WSH), Response.Flush (ASP), DoEvents (VB).
>
> Basically, I use:
>
> Call doStatus("Progress.")
>
> Sub doStatus(what)
> document.formHTA.Status.value = Now & what & vbCrLf & _
> document.formHTA.Status.value
> End Sub
>
> <form name="formHTA">
> <textarea name="Status" cols="50" rows="8" readonly></textarea>
> </form>
>
> Thanks in advance.
>
>
If you can stand using third party controls then scriptx from meadroid.com has
this facility as part of its free subset.

--

Joe (MVP)

https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17A5


McKirahan

unread,
Apr 14, 2005, 11:57:17 AM4/14/05
to
"Joe Fawcett" <joefa...@newsgroups.nospam> wrote in message
news:#SuJ$cQQFH...@TK2MSFTNGP12.phx.gbl...


Thanks for the reply.

I'm familiar with ScriptX; however, AFAIK, it's only for printing:

"ScriptX has been developed to provide absolute control over
document printing operations from client and server computers
running Microsoft's Internet Explorer browser on Windows."

I'm looking for a way to release resources during intensive
processing so that the HTA user interface can be updated.


Joe Earnest

unread,
Apr 14, 2005, 12:13:23 PM4/14/05
to
Hi,

"Joe Fawcett" <joefa...@newsgroups.nospam> wrote in message

news:%23SuJ$cQQFH...@TK2MSFTNGP12.phx.gbl...

So does AutoItX. It's my backup for WSCs, where the calling script fails to
hand the WScript property into the WSC object through a WSC property.

I've experimented with handing WScript into IE objects, as is routinely done
with WSCs, and found that you can hand it in, and it remains valid (it is
accessible when obtained by a second script from the IE window as a
pass-through to control the first script), until script in the IE window
attempts to use it in any way. Then it goes out of scope. I've assumed
that this indicates an IE security prohibition against the WScript object,
and not a basic problem with handling the WScript object.

I work almost exclusively with direct WSH-hosted script, WSCs and XML
script, not HTAs. I assume that there's no security prohibition against
WScript in HTAs (that is, that like XMLs, they can handle the object if they
can obtain it), but that you simply have no way to access it from inside the
HTA.

Is it possible to start your HTA with a WSH-hosted script and have the
script hand its instance of the WScript object into the HTA through an
argument? Just a guess. If it works, you'd have to keep the original
script alive for the duration of the HTA, since the derivative object would
go out of scope when the original script quits.

Regards,
Joe Earnest


Joe Fawcett

unread,
Apr 14, 2005, 1:33:32 PM4/14/05
to
"McKirahan" <Ne...@McKirahan.com> wrote in message
news:3qmdnT2iHqk...@comcast.com...
I've been using it to do this sort of thing for years. Especially useful for
showing an hourglass cursor whilst running long routines and showing progress
bars etc.

McKirahan

unread,
Apr 14, 2005, 2:24:47 PM4/14/05
to
"Joe Fawcett" <joefa...@newsgroups.nospam> wrote in message
news:O$RCVgRQF...@TK2MSFTNGP09.phx.gbl...

[snip]

> >> If you can stand using third party controls then scriptx from
meadroid.com
> > has
> >> this facility as part of its free subset.
> >>
> >> --
> >>
> >> Joe (MVP)
> >>
> >>
> >
https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17
> > A5
> >
> >
> > Thanks for the reply.
> >
> > I'm familiar with ScriptX; however, AFAIK, it's only for printing:
> >
> > "ScriptX has been developed to provide absolute control over
> > document printing operations from client and server computers
> > running Microsoft's Internet Explorer browser on Windows."
> >
> > I'm looking for a way to release resources during intensive
> > processing so that the HTA user interface can be updated.
> >
> >
> I've been using it to do this sort of thing for years. Especially useful
for
> showing an hourglass cursor whilst running long routines and showing
progress
> bars etc.
>
> --
>
> Joe (MVP)
>
>
https://mvp.support.microsoft.com/profile=8AA9D5F5-E1C2-44C7-BCE8-8741D22D17
A5
>

Don't you mean "AutoItX" or "ScriptX"?


Joe Fawcett

unread,
Apr 14, 2005, 3:59:35 PM4/14/05
to
>
> Don't you mean "AutoItX" or "ScriptX"?
>
>
ScriptX

--

Joe


McKirahan

unread,
Apr 14, 2005, 4:51:38 PM4/14/05
to
"Joe Fawcett" <joefa...@newsgroups.nospam> wrote in message
news:u3$k8xSQF...@TK2MSFTNGP12.phx.gbl...

"ScriptX: now the de facto printing control for the web, developed to


provide absolute control over document printing operations from client and

server computers running Internet Explorer. A subset of ScriptX printing and
script-enhancement functionality is available at no charge and is freely
distributable." http://www.meadroid.com/

How can a printer utility solve my problem?


Joe Fawcett

unread,
Apr 14, 2005, 5:03:16 PM4/14/05
to
"McKirahan" <Ne...@McKirahan.com> wrote in message
news:dIWdnUyPOsw...@comcast.com...
http://www.meadroid.com/scriptx/docs/gendocs.htm#factory
wait method

--

Joe


mayayana

unread,
Apr 14, 2005, 6:41:58 PM4/14/05
to
I use an external script, something like:

Sub Sleep(MSecs)
Ret = SH.Run("sleeper.vbs " & MSecs, , True)
end sub

from a script loaded by the page, or from the
page script itself. Since the page code can
create WScript.Shell it can run a file. That file
(sleeper.vbs) can then just be a simple:

Dim Arg
on error resume next
Arg = WScript.Arguments(0)
wscript.sleep Arg
--
_____________________________

mayayX...@mindYYspring.com
For return email remove XX and YY.
_____________________________


McKirahan <Ne...@McKirahan.com> wrote in message

news:woCdndg_x7W...@comcast.com...

McKirahan

unread,
Apr 14, 2005, 8:12:19 PM4/14/05
to
"Joe Fawcett" <joefa...@newsgroups.nospam> wrote in message
news:OUdbhVTQ...@TK2MSFTNGP09.phx.gbl...

Now I see ...

"Suspends (sleeps) the script execution for a specified timeout or
until CancelWait is called. Events are serviced during sleep."

But I'd like to avoid a 3rd-party utility as this is for a client and
I don't really like those kind of dependencies (if I can help it).

Thanks.


Clay Calvert

unread,
Apr 14, 2005, 9:33:24 PM4/14/05
to
On Thu, 14 Apr 2005 08:37:45 -0500, "McKirahan" <Ne...@McKirahan.com>
wrote:

>Is there an equivalent to one of the following that I could use?
>WScript.Sleep (WSH), Response.Flush (ASP), DoEvents (VB).

Alex Angelopoulos put this routine together.

t0 = timer
ccSleep 15
MsgBox timer - t0

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


Clay Calvert
CCal...@Wanguru.com
Replace "W" with "L"

Joe Earnest

unread,
Apr 14, 2005, 9:33:55 PM4/14/05
to
Hi,

"mayayana" <mayaXX...@mindYYspring.com> wrote in message
news:WkC7e.5697$go4....@newsread2.news.atl.earthlink.net...

That's a very nice workaround. I've used write-and-run secondary script
from WSCs and scripts to activate and modify modal windows, but just never
thought about using it for a Sleep alternative. Do you how much the file
write-and-run overhead adds to a short (say 50 ms) loop sleep? I also
suppose that there's considerable processor overhead using it for a looped
series of short sleeps?

I suppose that you could even get a WScript instance back into a WSC by
having the WSC write a zero-size IE window, running a secondary
write-and-run script that passes the object to the IE window, and then
having the WSC get the object from the IE window and kill the window. The
rub there would be keeping the secondary script alive, in order to use the
object, but killing it when the WSC closes unexpectedly.

Thanks for the idea,
Joe Earnest


Joe Earnest


McKirahan

unread,
Apr 14, 2005, 10:37:36 PM4/14/05
to
"mayayana" <mayaXX...@mindYYspring.com> wrote in message
news:WkC7e.5697$go4....@newsread2.news.atl.earthlink.net...
> I use an external script, something like:
>
> Sub Sleep(MSecs)
> Ret = SH.Run("sleeper.vbs " & MSecs, , True)
> end sub
>
> from a script loaded by the page, or from the
> page script itself. Since the page code can
> create WScript.Shell it can run a file. That file
> (sleeper.vbs) can then just be a simple:
>
> Dim Arg
> on error resume next
> Arg = WScript.Arguments(0)
> wscript.sleep Arg
> --
> _____________________________
>
> mayayX...@mindYYspring.com
> For return email remove XX and YY.

[snip]

Thanks! It works great. Here's (sort of) what I did:

Sub doCreate()
Const cVBS = "Sleep.vbs"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objCTF
Set objCTF = objFSO.CreateTextFile(cVBS,True)
objCTF.Write "WScript.Sleep 1"
Dim objWSS
Set objWSS = CreateObject("WScript.Shell")
End SUb

Sub doStatus(what)
document.formHTA.Status.value = Now & what & vbCrLf & _
document.formHTA.Status.value

document.formHTA.
objWSS.Run cVBS,,True ' <<<<<<<<<<<<<<<
End Sub

Sub doFinish()
Set objCTF = Nothing
Set objFSO = Nothing
Set objWSS = Nothing
End Sub

Call doStatus("Progress.")

<form name="formHTA">
<textarea name="Status" cols="50" rows="8" readonly></textarea>
</form>


This allows to me "Sleep" for 1 second in a single statement:

objWSS.Run cVBS,,True


McKirahan

unread,
Apr 14, 2005, 10:41:05 PM4/14/05
to
"Joe Earnest" <jearnes...@earthlink.net> wrote in message

[snip]

Thanks for your response.

I didn't fully understand what you were proposing ...
and then I saw mayayana's and implemented it easily.

McKirahan

unread,
Apr 14, 2005, 11:02:50 PM4/14/05
to
"McKirahan" <Ne...@McKirahan.com> wrote in message
news:BZmdnac5jdZ...@comcast.com...

Oops -- I did say "sort of"....

"Const cVBS" and "Dim objWSS" needs to be available globally:

Const cVBS = "Sleep.vbs"
Dim objFSO

Dim objCTF
Dim objWSS

Sub doCreate()


Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objCTF = objFSO.CreateTextFile(cVBS,True)
objCTF.Write "WScript.Sleep 1"

Set objWSS = CreateObject("WScript.Shell")

End Sub


mayayana

unread,
Apr 14, 2005, 11:41:41 PM4/14/05
to

> Do you how much the file
> write-and-run overhead adds to a short (say 50 ms) loop sleep? I also
> suppose that there's considerable processor overhead using it for a looped
> series of short sleeps?
>
I don't know about that kind of precision. I suppose
it must take several hundred ms to start up a script,
but I've never tested it. The one place that I've used it
is where I needed to call a zip program to unpack a file
and wanted to make sure that it had time to finish
before I proceeded; so I was sleeping it in terms of
seconds rather than ms.


mayayana

unread,
Apr 14, 2005, 11:45:27 PM4/14/05
to
I assume you mean sleep 1000 rather than
sleep 1. I hadn't thought of writing the file on
the spot, but that does make it all self-contained.

--
_____________________________

mayayX...@mindYYspring.com
For return email remove XX and YY.

_____________________________


McKirahan <Ne...@McKirahan.com> wrote in message

news:QcadnY0mx4c...@comcast.com...

McKirahan

unread,
Apr 14, 2005, 11:51:37 PM4/14/05
to
"mayayana" <mayaXX...@mindYYspring.com> wrote in message
news:rNG7e.7141$sp3....@newsread3.news.atl.earthlink.net...

> I assume you mean sleep 1000 rather than
> sleep 1. I hadn't thought of writing the file on
> the spot, but that does make it all self-contained.
>
> --
> _____________________________
>
> mayayX...@mindYYspring.com
> For return email remove XX and YY.

Actually, no; so I'm only sleeping for 1 millisecond
which is fine for my purposes!


Michael Harris (MVP)

unread,
Apr 15, 2005, 12:38:54 AM4/15/05
to
> Actually, no; so I'm only sleeping for 1 millisecond
> which is fine for my purposes!


In that case, this would problably serve your purpose just as well...

SH.Run "cmd.exe /c exit"

It's the call to Run that matters in this case, not what you run...

--
Michael Harris
Microsoft MVP Scripting
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Please ask follow-up questions via the original newsgroup thread.

McKirahan

unread,
Apr 15, 2005, 6:07:54 AM4/15/05
to
"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:e1bRHUXQ...@TK2MSFTNGP15.phx.gbl...


It's probably preferable as it doesn't require a file.

Shouldn't "%comspec%" be used instead of "cmd.exe"?
I often test under PWS on Win98SE which has "command.com".

However ... now that I'vr tested it there's a problem.
I get a black screen for a 2+ seconds -- bad!!

Here's a test script; any thought?

<html>
<head>
<title>Comspec.hta</title>
<script type="text/vbscript">
Sub Comspec()


Dim objWSS
Set objWSS = CreateObject("WScript.Shell")

objWSS.Run "%comspec% /c exit",,True


Set objWSS = Nothing
End Sub

</script>
</head>
<body>
<input type="button" value="Comspec()" onclick="Comspec()">
</body>
</html>


Joe Earnest

unread,
Apr 15, 2005, 8:34:59 AM4/15/05
to
Hi,

"McKirahan" <Ne...@McKirahan.com> wrote in message

news:rsydnRPA7Kj...@comcast.com...


You can add a screen parameter (0) to hide the black screen.

objWSS.Run "%comspec% /c exit",0,True

I'm puzzled by the 2+ seconds, however - this should just be a quick flash,
even with the screen display. (It is on both my XP and 98 machines).

Dropping the final True seems to give a shorter delay. The script will
delay long enough to run cmd.exe or command.com in either case; it just
won't wait for the command processor to exit.

Regards,
Joe Earnest

McKirahan

unread,
Apr 15, 2005, 9:20:28 AM4/15/05
to
"Joe Earnest" <jearnes...@earthlink.net> wrote in message
news:ej9CLebQ...@TK2MSFTNGP12.phx.gbl...

It's the same behavior with or without the "0".


Joe Earnest

unread,
Apr 15, 2005, 12:03:27 PM4/15/05
to
Hi,

"McKirahan" <Ne...@McKirahan.com> wrote in message

news:t7GdnWZo8o_...@comcast.com...

Well, that's particularly puzzling. I tested it in your test HTM on my
computer, and it worked fine. I don't know why the hidden window code would
fail.

Maybe just do something else that eats up time, like a long loop
(particularly if you really just need a millisecond).

for i=1 to 32767
next

You can adjust it to whatever length you need. The disadvantage, as I
understand it, to a simple loop, is that it can peg processor usage.
Windows allocates time slices for file operations, so I suspect that any
file operation that takes a bit of time and doesn't have a window, such as
creating a temp file, or opening and closing a file, might work better.

Regards,
Joe Earnest


Michael Harris (MVP)

unread,
Apr 15, 2005, 8:25:34 PM4/15/05
to
> Maybe just do something else that eats up time, like a long loop
> (particularly if you really just need a millisecond).

I don't think McKirahan's objective to consume any time at all but rather to
break the modality of the long running event handler in order to allow the
UI to render changes...

McKirahan

unread,
Apr 16, 2005, 12:17:20 AM4/16/05
to
"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:#raoMrhQ...@TK2MSFTNGP15.phx.gbl...


Exactly.

But I'd like to get your solution to work without the 2+ second black
screen.

The advantage would be that a file isn't involved.


rgf

unread,
Apr 26, 2005, 11:47:43 AM4/26/05
to
McKirahan wrote:

> "Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
>

>>>Maybe just do something else that eats up time, like a long loop
>>>(particularly if you really just need a millisecond).
>>
>>I don't think McKirahan's objective to consume any time at all but rather to
>>break the modality of the long running event handler in order to allow the
>>UI to render changes...
>>
>>--
>>Michael Harris
>>Microsoft MVP Scripting
>>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>>Please ask follow-up questions via the original newsgroup thread.
>
> Exactly.
>
> But I'd like to get your solution to work without the 2+ second black
> screen.
>
> The advantage would be that a file isn't involved.

Had the same kind of problem in a WSC. I could solve it by using the ooRexx sleep function, which
implies installing ("one-click install") another scripting language (cf. http://www.ooRexx.org, free
and opensource) which offers that functionality.

In the case of the WSC (Windows Script Component) I had the problem that a MS Access database could
have been accessed by different instances concurrently, so if two instances hit the same lock, they
were suppossed to sleep a different short time before attempting to access the database again in a
fashion which did not cause additional dead-locks or racing conditions).

Having had coded everything in VBScript I was lost at first, until I thought about the new ooRexx
which is easy to learn and use (it's like pseudo code).

In order to use ooRexx one needs to merely insert another script-tag, indicating that ooRexx
(registered ActiveX-script name is "Object Rexx") is used within and define a public routine.

Microsoft's Windows script support is rather nice in that it allows to call functions written in any
ActiveX-scripting language. So here's the code in that case that I "injected" into the WSC to supply
the sleep function to VBS:

<script language="object rexx">
<![CDATA[
-- Open Object Rexx needed for getting access to the sysSleep() function!
::routine rgfSleep public -- define routine to be public
use arg sleepTime -- get upper sleepTime limit (e.g. "0.005" for 5 msecs)
call sysSleep sleepTime -- sleep msec
]]>
</script>

Here is the snippet from VBScript to invoke the above routine:

rgfSleep sleepTime ' call ooRexx to sleep "sleepTime" seconds or fraction thereof


---

Also I use ooRexx to create beeps (some "melodies" to notify the users of specific events) from
VBScript in HTAs, here an example:


<script language="Object Rexx">

::routine beep4vbs public -- define a public routine for beeping
use arg kind -- retrieve kind of beep/melody to play

if kind=1 then -- o.k. tone, single low beep
do
call beep 100, 100 -- freq/dur
end

else if kind=2 then -- Alarm: stop "melody"
do
dur=10
do i=1 to 10 -- repeat ten times
do j=500 to 11500 by 500
call beep j, dur
end
do j=i to 500 by -500
call beep j, dur
end
end
end

else if kind=3 then -- Alarm: notify "melody"
do
dur=10
do i=1 to 15 -- repeat fifteen times
do j=500 to 3500 by 500
call beep j, dur
end
do j=i to 500 by -500
call beep j, dur
end
end
end

else if kind=4 then -- any other kind, high beeps
do
do 5 -- repeat five times
call beep 2500, 10
end
end
</script>

---

Again, it involves installing a (free and opensource) scripting language from
<http://www.ooRexx.org>, but that is really easy ("one click install").

Maybe this helps a little bit,

---rony

Joe Earnest

unread,
Apr 26, 2005, 3:08:50 PM4/26/05
to
Hi,

[snipped]

"rgf" <rony.fl...@wu-wien.ac.at> wrote in message
news:ektoKdn...@TK2MSFTNGP12.phx.gbl...


> Had the same kind of problem in a WSC. I could solve it by using the
> ooRexx sleep function, which implies installing ("one-click install")
> another scripting language (cf. http://www.ooRexx.org, free and
> opensource) which offers that functionality.

Just for future reference, although WSC doesn't have inherent access to the
WScript object, you can easily pass the WScript object into a WSC through a
property, and use it for its Sleep method. You don't need to go to a
different language.

Joe Earnest


rgf

unread,
Apr 27, 2005, 8:17:03 AM4/27/05
to

Interesting, thank you for this hint. But would that work reliably, if the clients are instantiating
the WSC via DCOM, i.e. residing on a physical different, remote PC, possibly running different
versions of Windows (resp. different versions of WSH, if they have not updated to the latest SP or
MSIE)?

Also, is there a way to get at primitive beep()-functionalities (this would be important for the HTA
side of it), to allow for playing primitive tones/melodies?

---

Having to install ActiveX components would be fine (which ones would be free and available, did try
to research this first, unfortunately, to no avail), but in that case it would be of equal
"disturbance" as installing an additional language supplying these (missing!) functions. [Besides,
now I have a tool to interrogate the published COM-interfaces and have them rendered into a nice
concise HTML-page.]

Regards,

---rony

Joe Earnest

unread,
Apr 27, 2005, 10:00:56 AM4/27/05
to
Hi,

[interlineated response]

"rgf" <rony.fl...@wu-wien.ac.at> wrote in message

news:uZeRHMyS...@tk2msftngp13.phx.gbl...


>> "rgf" <rony.fl...@wu-wien.ac.at> wrote in message
>> news:ektoKdn...@TK2MSFTNGP12.phx.gbl...
>>
>>>Had the same kind of problem in a WSC. I could solve it by using the
>>>ooRexx sleep function, which implies installing ("one-click install")
>>>another scripting language (cf. http://www.ooRexx.org, free and
>>>opensource) which offers that functionality.
>>
>>
>> Just for future reference, although WSC doesn't have inherent access to
>> the WScript object, you can easily pass the WScript object into a WSC
>> through a property, and use it for its Sleep method. You don't need to
>> go to a different language.
>
> Interesting, thank you for this hint. But would that work reliably, if the
> clients are instantiating the WSC via DCOM, i.e. residing on a physical
> different, remote PC, possibly running different versions of Windows
> (resp. different versions of WSH, if they have not updated to the latest
> SP or MSIE)?

To work, the WSC has to be instantiated from WSH-hosted script (e.g., not
inside HTML). So long as that limitation is understood, it will work
consistently.

Here's a version of the standard property (put) function for the WSH
property that I use to set the global oSleep object variable and fSleep
global flag in my WSCs.

-----
function Wsh (poWScript)
if isobject(poWScript) then
if (poWScript.name="Windows Script Host") then
on error resume next
set oSleep= poWScript
fSleep= (err=0)
on error goto 0
end if
end if
end function
-----

From the calling script, this is handled as a routine part of initiation --
but it does require the property assignment.

-----
'createobject or getobject per registration

set oWsc= createobject(...)
oWsc.wsh= wscript
-----

Since this is the calling script's instance of the WScript object that is
passed in, the WSC can use the object for inherent access and control over
aspects of the calling script, including the calling script's Arguments
collection, the script name and path, and even QUIT.

This has been the subject of a couple of long threads in the NG several
years' back, but AFAIK no one's come up with a way to access WScript
automatically without the pass-in. For example, the WSC could write and run
a secondary script to call the WSC and pass its WScript object, but since
WSCs aren't singletons, the object is passed to a different instance of the
WSC object; etc.

> Also, is there a way to get at primitive beep()-functionalities (this
> would be important for the HTA side of it), to allow for playing primitive
> tones/melodies?

I'm not aware of how you'd directly get the QuickBASIC or VB BEEP-equivalent
pitch and duration.

The standard ways of playing a single "beep" are the following (credit
Torgeir Bakken posts). I'd think you would just create the wave file melody
or complex beep that you want and run it.

-----
sWav = "%windir%\media\ding.wav"
oWshShell= createobject("wscript.shell")
oWshShell.run "sndrec32 /play /close """ & sWav & """", 0, true
-----

or

-----
set oWshShell= createobject("wscript.shell")

beep 1, 0

sub Beep (unBeeps, ufWait)
for i = 1 to unBeeps
oShell.Run "%comspec% /c echo " & Chr(7), 0, false
wscript.sleep ufWait
next
end sub
-----

>
> ---
>
> Having to install ActiveX components would be fine (which ones would be
> free and available, did try to research this first, unfortunately, to no
> avail), but in that case it would be of equal "disturbance" as installing
> an additional language supplying these (missing!) functions. [Besides, now
> I have a tool to interrogate the published COM-interfaces and have them
> rendered into a nice concise HTML-page.]

AutoItX is a great little freeware COM for manipulating windows, keyboard
input and mice, and several other utility functions. It has a Sleep method
that's idenctical to WScript. I install AutoItX on all my computers, and my
WSCs automatically check for it. This would obviate the need to pass the
WScript object into the WSC, and would also make it available in
non-WSH-hosted script (such as HTML).

http://www.autoitscript.com/autoit3/downloads.php

As mentioned by Joe earlier in this thread, the freeware component of
ScriptX (the best HTML printing utility COM) has a Wait method that's
functionally identical to WScript.Sleep, with an added ability to sleep
indefinitely, which is useful for spin-off scripts. Since the method name
is different, if you don't know whether you're getting a Sleep or a Wait
method (i.e., which is available on the host computer), you'd need to check
for both and wrap them in a WSC function, which you could call for the
action.

http://www.meadroid.com/scriptx/index.asp

I'm sure there are other freeware COMs out there with sleep methods, since
any number of people "roll their own" and post them on websites. You might
also want to look at DynaCall, which lets you make API calls in script.
Unfortunately, it's terribly awkward, and requires you to know the API call
parameters, but it's very useful when there's no other way to get the job
done. Of course, you also have to have DynaCall installed on the host
computer.

This is Guenter Born's version and excellent explanation of the history and
use of DynaCall:

http://www.borncity.com/WSHBazaar/WSHBazaar.htm

>
> Regards,
>
> ---rony

Regards,
Joe Earnest


rgf

unread,
Apr 27, 2005, 4:52:05 PM4/27/05
to
Joe:

thank you very much for your detailed posting carrying a lot of useful information!

Regards,

---rony

tlav...@hotmail.com

unread,
Apr 27, 2005, 6:12:21 PM4/27/05
to
I realize I am very late to this thread, but I haven't seen any mention
of the setTimeout or setInterval methods provided by the HTA DOM. They
are not easy to program, but they are intrinic to HTA (as well as
HTML).

The main issue is that to work the code must issue the setTimeout or
setInterval and then end its own process. Here is a quicky examole I
wrote for another post a long time ago ...

<html>
<head>
<script language=VBScript>
Sub StepWise(nStage)

Select Case nStage
Case 1
document.body.innerHTML = "Step " & nStage
setTimeout "StepWise " & nStage + 1, 1000, "VBScript"
Case 2
document.body.innerHTML = "Step " & nStage
setTimeout "StepWise " & nStage + 1, 1000, "VBScript"
Case 3
document.body.innerHTML = "Step " & nStage
setTimeout "StepWise " & nStage + 1, 1000, "VBScript"
Case 4
document.body.innerHTML = "Step " & nStage
setTimeout "StepWise " & nStage + 1, 1000, "VBScript"
Case 5
document.body.innerHTML = "Done"
End Select

End Sub

</script>
</head>
<body onload="StepWise 1">
</body>
</html>

Save it as an HTA file and it will run as such. I just left out the
header stuff.

It just changes the message count every second for four seconds and
shows "Done" after five seconds, but it illustrates the approach.

It's not as easy as a wsh.Sleep, but it is intrinsic.

Tom Lavedas
=============

Tom Ker

unread,
May 3, 2005, 1:47:31 PM5/3/05
to
Tom,

Thanks for posting that code. I'm trying to use it and not getting the
results I think I should get.

In VBS I use the following code to display a blinking message in an IE
window during an EXEC operation. It calmly throbs "Please Wait" under some
discriptive message as the EXEC does it's thing.

<snip>
i = 1
Do While oExec.Status = 0
If i mod 2 = 0 Then
oMsgIEDiv1.InnerHTML = sMsgPart1
oMsgIEDiv2.InnerHTML = "Please Wait."
Else
oMsgIEDiv1.InnerHTML = sMsgPart1
oMsgIEDiv2.InnerHTML = ""
End If
oShell.AppActivate sTitle
Wscript.sleep 750
i = i + 1
loop
<snip>

When I try to convert that script to an HTA using the code below I get a
rather spastic wildly blinking "Please Wait". Seems to me, after reading
about setTimeout, that I should actually have a slightly slower throb with
this code instead of the almost seizure enducing strobe effect that I get
now. It doesn't seem to matter what number of milliseconds I use either.

<snip>
i = 1
Do While oExec.Status = 0
If i mod 2 = 0 Then
oMsgIEDiv1.InnerHTML = sMsgPart1
oMsgIEDiv2.InnerHTML = "Please Wait."
Else
oMsgIEDiv1.InnerHTML = sMsgPart1
oMsgIEDiv2.InnerHTML = ""
End If
oShell.AppActivate sTitle
setTimeout "Sleeper " & i, 1000, "VBScript"
i = i + 1
loop
<snip>

Sub Sleeper(i)
'do nothing
End Sub

Any suggestions will be greatly appreciated. Thanks,

Tom


Malcolm McCaffery

unread,
Jun 9, 2007, 10:06:56 PM6/9/07
to
This is what I use:

' Sleep for HTA by Malcolm McCaffery
Sub Sleep(intMilliSecs)
CONST HideWindow=0
CONST WaitForCompletion=TRUE

' Because HTA doesn't use Windows Script Host, it uses IE Script Host we
can't use WScript.Sleep
' Workaround: send one ping command to fake address with a wait for reply
value set in milliseconds
cmd="cmd /c ping 1.1.1.1 -n 1 -w " & intMilliSecs
With CreateObject("WScript.Shell")
.Run cmd,HideWindow,WaitForCompletion
End With
End Sub

Michael Harris (MVP)

unread,
Jun 10, 2007, 12:13:58 AM6/10/07
to

If this is for personal use, you could always install ScriptX (has a Wait
method) or AutoItX (has a Sleep method) - both are free.

Personally, I'm using the AutoItX v3 COM object...

Set aux = CreateObject("AutoItX3.Control")
aux.sleep 10000


--
Michael Harris
Microsoft.MVP.Scripting


rickety

unread,
Jun 11, 2007, 12:02:47 PM6/11/07
to
On Jun 10, 12:13 am, "Michael Harris \(MVP\)" <mikhar.at.mvps.dot.org>
wrote:
> Microsoft.MVP.Scripting- Hide quoted text -
>
> - Show quoted text -

There is another workaround that you may find interesting, using the
setTimeOut function of the DOM

Function Blahblah
.....
IntervalMarker = setTimeout("CarryOn", 50, "vbscript")
End Function
'
' ===== carries on from above when interval expires
' this "feature" allows the updated status message to be
' rendered and viewed by the user
'
Function CarryOn ' Code to be executed after the
delay
... more of this function
End Function

Digiman57

unread,
Jun 13, 2007, 9:07:09 AM6/13/07
to
THis is a script that works in an HTA script. You end up calling the CCsleep
sub

'set i for 6 seconds then call sub Counter1(i) which calls ccsleep
i = 6
Call Counter1(i)

Sub Counter1(i)

While i <> 0

i=i-1
DataArea.InnerHTML = "Ready to open txt file in <b>" & i & "</b> seconds."
t0 = Timer
ccSleep 1
Wend
'Call getMachineType
'MsgBox timer - t0
window.close
End Sub

'__________________________________________________________________________________________________
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

"rickety" wrote:

> ......


> IntervalMarker = setTimeout("CarryOn", 50, "vbscript")
> End Function
> '
> ' ===== carries on from above when interval expires
> ' this "feature" allows the updated status message to be
> ' rendered and viewed by the user
> '
> Function CarryOn ' Code to be executed after the
> delay

> .... more of this function
> End Function
>
>

Alex

unread,
Oct 15, 2009, 3:07:29 PM10/15/09
to
To use WScript in HTA you can try this HACK.

http://forum.script-coding.info/viewtopic.php?pid=29243#p29243

main.hta starts wscript.vbs and connects to it's WScript object.

This code doesn't need any third party COM objects. Only standart components.


P.S In this post you also can find how to connect one or more HTA files and
hook events from each other anywhere you need.

url:http://www.ureader.com/msg/1675551.aspx

0 new messages