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

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



Re: Running Wscript in HTML by \

\
Mon Jul 07 12:41:17 CDT 2003

>The short answer is you can't.

That's what I was afraid of.

>So, what can you use instead of WScript.Sleep? You can use
>window.setTimeout() instead, e.g,

Yes, I'm familiar with setTimeout and setInterval. They are awkward to use in
some situations, and I was just using "sleep" as one example of a Wscript
function.

What is confusing is if Wscript is not available in a HTML script, how does
"Wscript.Shell" work?

Dave



Re: Running Wscript in HTML by Tom

Tom
Mon Jul 07 13:07:16 CDT 2003

The Wscript objects are hosted in at least three places:
Wscript.exe (or cscript.exe), wsh.ocx and scrrun.dll. The
EXE host object cannot be accessed from HTML, while the
objects supplied by the latter two can be (with
significant security restrictions).

AFAIK, the only object hosted by the EXE is Wscript.
Thus, anything that is accessed by reference to 'Wscript.'
(Wscript.Echo, .Popup, .Sleep, etc) is unavailable when
WSH is not the host. However, anything that requires an
explicit object instantiation (e.g. CreateObject
("Wscript.Shell")) is available on the client side
(assuming WSH is loaded), except for the security issues.
ASP's can use them on the server side vis
Server.CreateObject(), with some permission issues.

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

>-----Original Message-----
>>The short answer is you can't.
>
>That's what I was afraid of.
>
>>So, what can you use instead of WScript.Sleep? You can
use
>>window.setTimeout() instead, e.g,
>
>Yes, I'm familiar with setTimeout and setInterval. They
are awkward to use in
>some situations, and I was just using "sleep" as one
example of a Wscript
>function.
>
>What is confusing is if Wscript is not available in a
HTML script, how does
>"Wscript.Shell" work?
>
>Dave