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

WScript Sleep in HTML

404 views
Skip to first unread message

Bruce Hensley

unread,
Sep 13, 2004, 2:14:40 PM9/13/04
to
Is there a way to make the WScript Sleep method available to client-side
VBScript in an HTML page (for use on a company intranet with all systems
using Win 2000 and IE 6)?

TIA,
Bruce


Tom Lavedas

unread,
Sep 13, 2004, 3:49:06 PM9/13/04
to
No.

An HTML will need to make use of the setInterval or setTimeout methods of
the DOM.

Here are some historical discussions that include or focus on this topic:

http://www.google.com/groups?q=setinterval+author:lavedas&hl=en&lr=&ie=UTF-8&scoring=d

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

Michael Harris (MVP)

unread,
Sep 13, 2004, 7:08:47 PM9/13/04
to
Tom Lavedas wrote:
> No.
>
> An HTML will need to make use of the setInterval or setTimeout
> methods of the DOM.
>


Or use a 3rd party component like ScriptX from www.meadroid.com. It has a
Wait method in the free unlicensed feature subset...

> Here are some historical discussions that include or focus on this
> topic:
>
>
http://www.google.com/groups?q=setinterval+author:lavedas&hl=en&lr=&ie=UTF-8&scoring=d
>
> Tom Lavedas
> ===========
>
> "Bruce Hensley" wrote:
>
>> Is there a way to make the WScript Sleep method available to
>> client-side VBScript in an HTML page (for use on a company intranet
>> with all systems using Win 2000 and IE 6)?
>>
>> TIA,
>> Bruce

--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US

mayayana

unread,
Sep 13, 2004, 7:44:27 PM9/13/04
to
If your security can allow WScript.Shell to run
you can do it this way -

Script sub in webpage:

<SCRIPT LANGUAGE="VBScript">
Sub Sleep(NumberSeconds)
Dim SH, Ret
Set SH = CreateObject("WScript.Shell")
Ret = SH.Run("sleeper.vbs " & NumberSeconds, , True)
End Sub
</SCRIPT>

In the same folder as the webpage, put a file named
sleeper.vbs and put this code into it:

Dim Arg
on error resume next
Arg = WScript.Arguments(0) * 1000
WScript.sleep Arg

You can then call something like:

Sleep 5 '-- pauses 5 seconds.

--
--
Bruce Hensley <nobody@nowhere> wrote in message
news:ubSFK2bm...@TK2MSFTNGP09.phx.gbl...

Bruce Hensley

unread,
Sep 15, 2004, 3:30:35 PM9/15/04
to
mayayana,

Thanks for the good suggestion. However, sleeper.vbs doesn't appear to run
(I tried replacing its content with a msgbox line, with no result), though
there are no error messages. The main script just seems to abort at the run
command with no error reported.

Perhaps it is a security issue. I'll pursue this.

Thanks,
Bruce

"mayayana" <mayaXX...@mindYYspring.com> wrote in message
news:vhq1d.727$n16...@newsread2.news.atl.earthlink.net...

mayayana

unread,
Sep 15, 2004, 5:42:23 PM9/15/04
to
> sleeper.vbs doesn't appear to run
> (I tried replacing its content with a msgbox line, with no result), though
> there are no error messages. The main script just seems to abort at the
run
> command with no error reported

It would be the same security issue with the MsgBox,
since you still need to use WScript.Shell to run the script.
It sounds like you probably have
"Initialize and script ActiveX controls not marked as safe"
set to Disable instead of the default setting of Prompt.
I'm guessing that on your network you don't have the option
to change that, in which case you wouldn't be able to use
WScript.Shell from your page at all.

Also, there's some limitation with this Sleep method.
It works fine if security allows it but since it probably takes
a few hundred ms to create Shell and run the script
(I've never actually timed it.), this method wouldn't work very
well for the kind of situation where you want to use, say,
Sleep 100 '--ms
numerous times in the course of a function.

If you are free to reset security and want to, you can make
local security settings visible in the IE security window with the
following:

Set SH = CreateObject("WScript.Shell")

sReg = "Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\0\Flags"
SH.RegWrite "HKLM\" & sReg, 33, "REG_DWORD"
SH.RegWrite "HKCU\" & sReg, 33, "REG_DWORD"
Set SH = Nothing

(The Flags value is a bit flag. 1 is configurable. 32 is visible.
Thus 33.)

You can also enable
"Initialize and script ActiveX controls not marked as safe"
on the local machine with:

Set SH = CreateObject("WScript.Shell")

sReg = "Software\Microsoft\Windows\CurrentVersion\Internet
Settings\Zones\0\1201"
SH.RegWrite "HKLM\" & sReg, 0, "REG_DWORD"
SH.RegWrite "HKCU\" & sReg, 0, "REG_DWORD"
Set SH = Nothing


Bruce Hensley

unread,
Sep 15, 2004, 6:27:10 PM9/15/04
to
Tom,

Thanks for the references. I'd seen many of them, but hoped someone had
found a workaround.

The approach with routine1 and routine2 seperated by a pause doesn't quite
fit the need because I need to repeat the pause in a loop indefinitely
(until a condition is met), like this ...

Dim oIE
Set oIE = createobject("internetexplorer.application")
oIE.navigate "href of very slow page"
oIE.Visible = True

Do until oIE.readystate = 4
< .. pause for a short period to save cycles ..>
Loop
<.. continue here ..>

So, I've been trying to do it with setinterval, but can't seem to get it to
work, sort of like this ...

Dim Interval
Interval = window.setinterval("IsReady", 100, "vbscript")
<.. continue here ..>

Function IsReady()
If (oIE.readystate = 4) then
window.clearinterval Interval
End If
End Function

I thought this should call IsReady every 200 msecs, but it seems to return
immediately.

Thanks for your help.

Bruce

"Michael Harris (MVP)" <mikhar at mvps dot org> wrote in message
news:Ovw0haem...@TK2MSFTNGP09.phx.gbl...

Bruce Hensley

unread,
Sep 15, 2004, 6:35:04 PM9/15/04
to
mayayana,

Actually, we have the setting you mention set to Enable for the local
intranet (one place I tried it) and trusted sites (another place I tried
it), and to Prompt for the Internet. All the rest of the ActiveX settings
are set to Enable for all three zones.

Thanks,
Bruce

"mayayana" <mayaXX...@mindYYspring.com> wrote in message

news:3H22d.2762$mb6...@newsread3.news.atl.earthlink.net...

mayayana

unread,
Sep 15, 2004, 10:18:21 PM9/15/04
to
That's odd. The only other things I can think of are
the Active Scripting setting and the possibility that
the file path is somehow not valid.
(It can only run as the " Ret = SH.Run("sleeper.vbs " ....
version if the script is in the same folder with the webpage.)

--
--
Bruce Hensley <nobody@nowhere> wrote in message

news:ezz$AR3mEH...@TK2MSFTNGP11.phx.gbl...

name

unread,
Sep 16, 2004, 1:10:46 AM9/16/04
to
There is a "waitfor" exe.

And there is (are) "waitfor" third party dll(s).

-------

Don't know lots about the 'official' ms one.

===========

The third party one however worked well;

and let to suspension from (by) google for a month.

+++++++

And that is not official.

=========

While running a two hour script to analyze which groups where
indexed re: visitors/stats etc, AOL had tons of
"aol.neighborhood.my.dog.eats"
and the script got stuck with a 'warning' and 'block' in there.

I have had a static for many years and did not trick anything.
I send g a letter, indicating I'd waitfor a better solution of theirs.

-------

WSH will do nothing in a webpage that will give you 'sleep'.

That is official.

Same as wsh without binary and file find wildcard
is now considered a MS training tool for getting
self-trained 'loopers' to buy 'developer products'

Sincerely

"Bruce Hensley" <nobody@nowhere> wrote in message

news:ubSFK2bm...@TK2MSFTNGP09.phx.gbl...

Tom Lavedas

unread,
Sep 16, 2004, 1:01:13 PM9/16/04
to
I know that this is a complicated subject. It took me a while to
figure out how to use it, too. The problem is that to have this work,
your calling subroutine must END after you set up the setInterval AND
then the called routine must call a new subroutine (or the old one
with a re-entry argument to control branching).

For example ...

' Declare global variables
Dim oIE
Dim Interval
' if this is to execute 'onload' your code/event will need to initiate
the
' FirstRoutine to set the ball rolling. But in either case, the
setInterval
' must be setup in the 'onload' code and then that routine must reach
its end.

Sub FirstRoutine(arguments)


Set oIE = createobject("internetexplorer.application")

Interval = window.setinterval("WaitUntilReady", 100, "vbscript")


oIE.navigate "href of very slow page"

End sub

Sub WaitUntilReady()


If (oIE.readystate = 4) then window.clearinterval Interval

ContinueRoutine ' or FirstRoutine with argument to branch to
second part
End Sub

Sub ContinueRoutine
' The load is now complete
oIE.Visible = True
' now do the rest of the stuff
End Sub

Hope that helps.

BTW, is this in an HTA? I don't quite understand the logic of using
the IE.App object. It causes security issues in an HTML, doesn't it?
Why are you not using a frame or a window.open which is directly
supported by the DOM in both HTML and HTA?

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

"Bruce Hensley" <nobody@nowhere> wrote in message news:<#S$wmM3mE...@TK2MSFTNGP12.phx.gbl>...

Bruce Hensley

unread,
Sep 17, 2004, 10:53:11 AM9/17/04
to
Tom,

Thanks for being so patient. I think I just got it! Please correct me if
I'm wrong ...

SetInterval starts executing the sub or function in its call on a repeating
schedule, but it is done asynchronously; that is, immediately following the
call to SetInterval, execution of the script continues with the next command
after the SetInterval, while the SetInterval simultaneously continues to
send its repeated calls.

If so, this will not achieve my goal, which was to pause the script. The
reason for pausing the script is that IE throws an "error" ("A script on
this page is causing Internet Explorer to run slowly...") with the following
code (which works fine from a VBS) ...

do until oIE.readystate = 4
loop

I guess I'll stick with the Ping approach (which works even though it looks
silly) ...

'wait til page is loaded
Do until oIE.readystate=4
Sleep 1
Loop

Sub Sleep(seconds)
'pause script about 1 second
Set oWSShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oWSShell.Run cmd,0,1
End Sub

To not exactly answer your questions ... no, this is an HTML file that is
closed after it runs. Its purpose is to load another slow-to-load page,
wait for it to complete loading, then populate its form fields and submit
it. I have had no security issues, but this is run from a trusted site in
our intranet. I am not using an HTA or window.open or frame, because I
didn't think of it ... being a newbie and all.

Thanks again,
Bruce

"Tom Lavedas" <tlav...@hotmail.com> wrote in message
news:b86eca15.04091...@posting.google.com...

Tom Lavedas

unread,
Sep 17, 2004, 11:55:08 AM9/17/04
to
Yes, setInterval is running asynchronusly. That's why your script needs
to be cut into two parts - to effect the pause. I believe the example I
posted does exactly that.

Using the ping is up to you, but the setInterval will also work.

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

0 new messages