Re: Running Wscript in HTML by Oisin
Oisin
Mon Jul 07 11:24:19 CDT 2003
The short answer is you can't. When you run a js/wsf/vbs file outside of a
web page, the scripting host is cscript.exe or wscript.exe. It is this host
that provides access to the intrinsic object "WScript". When you run within
a web page, Internet Explorer becomes the host and you will not have access
to WScript, only IE objects.
So, what can you use instead of WScript.Sleep? You can use
window.setTimeout() instead, e.g, to perform sequential tasks inside the
browser that need to sleep between them, use:
<script language=vbscript>
Dim wsh, ret
wsh = CreateObject("WScript.Shell")
Sub Main(sState)
Select Case sState
Case "running":
if ret.status = 0 then
window.setTimeout("Main(""running"")", 50) ' try again in
50ms
else
Main("complete")
Case "complete":
window.status = "complete."
Case Else:
' start work here
ret = WshShell.run("e:\wallpaper\scripts\webread.vbs",0,true)
window.status = "running..."
window.setTimeout("Main(""running"")", 50)
End Select
End Sub
Main ' go!
</script>
This came out of my head, so hopefully there aren't any typos. There's no
point polling any more frequently than 50ms, a typical machines timer
resolution in no better than 15ms, and inside the browser environment it's
probably way worse than that. As you can see, it is a little convoluted --
you should probably stick to a vbs script run through wscript.exe if you can
help it.
Hope this helps,
- Oisin
""Crash" Dummy" <dvader@deathstar.mil> wrote in message
news:utXoW3JRDHA.2460@TK2MSFTNGP10.phx.gbl...
> I don't have any trouble creating and using a Wscript shell in a web page
(with
> appropriate permissions), but I can't run Wscript functions. For example,
this
> works fine:
>
> Set WshShell = CreateObject("WScript.Shell")
> ret=WshShell.run("e:\wallpaper\scripts\webread.vbs",0,true)
>
> But if I try to run "Wscript.sleep 10," I get an error telling me there is
no
> Wscript object. How can I instantiate a Wscript object in a HTML file?
>
> Dave
>
>
>