Re: WScript.dll not working

Tech-Archive recommends: Fix windows errors by optimizing your registry



Abhishek wrote:
I am trying to put a delay of 5 seconds in my VBScript using WScript.Sleep 5000.
This works fine with the independent .vbs file. But, when i call a script indirectly in my application's exe's context, then it doesn't repond further.


hi Abhishek,

As has already been said, the sleep method is coded into the
WScript object and not available from any other host. I suspect
that your app may be running your script via the Windows Script
Control.

All that aside, your question is frequently asked here, and there
are dozens (maybe hundreds) of alternative ways to "wait-a-bit".

The most straight-forward way, (for you), is to get the app vendor
to write a homebrew "WScript Object", with a sleep method, and
implant that into the script control's object library. Then you
could just call it as you would running under the wscript host.

If the app vendor is not willing to go along, then there are
other alternatives, running from the ridiculous-to-the-sublime.

In the ridiculous category: read the system clock. Then go into
a loop, and continue reading the system clock. When 5 seconds
have passed, then exit the loop.

You could use a (hidden) instance of IE. There are several
suggestions relating to scripting inside IE. For one, you can
use IE to set a timer to 5 seconds duration. When the timer
event is called, then exit IE and continue with your script.

You could also use a (hidden) instance of ms WD or XL. Or,
any other ms app with VBA, for that matter. There are postings
here of how to start up WD or XL, insert a macro with a system
api call to the sleep api, execute the macro, and then return
to your script.

Moving along, if you are courageous enough or foolhardy enough
to use a 3rd-party control and call a system api, then you
could call the sleep api directly from script.

Nota bene: the wsh sleep method is not just a simple call to
the sleep api. The sleep api works well enough for sleeps of
a short duration, but for longer sleeps you could hang your
system. That's because the system sends out messages that it
expects well-behaved apps to respond to. For example, the
shutdown message and the memory move message. And so, the
wsh sleep method is really coded as a loop. In essence, it
does a sleep (api) then a "DoEvents" call, i.e., it pauses
to allow for event processing, then another sleep and another
DoEvents, and so on. So if you do use system api's in script
to implement your own sleep method, then be sure to allow for
event processing, if the sleep is longer than short duration.

If you can write-yer-own actX object, then you can write a
simple object what will duplicate the wsh sleep method.

Now for the sublime. There is wscript.exe (containing sleep)
and the IHost interface (typelib) there in your registry.
VBScript (for whatever reason) does not allow you to
instantiate WScript (i.e., the IHost interface) with
"CreateObject". However, it can be done using the "internal
way" that microsoft uses to instantiate an object. You load
the module, get the interface, and then invoke the call.
This is only for COM experts. And since you could be one
of them, I thought I would include this.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)

.



Relevant Pages

  • Re: Sleep command quitting
    ... It cannot be that the `sleep` command is terminating. ... That script was popular when I started working at SCO Support in 1989. ... it doesn't really hold the settings you specify. ... anything else comes along and makes further changes, the holdopen script ...
    (comp.unix.sco.misc)
  • my script crashes when I try to rename the file!
    ... OK, thanks, but the script does not seem to rename the files. ... You can set the working directory from within your Perl ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (perl.beginners)
  • More on perl like tail
    ... If I write my script based on this code... ... But first about that sleep comment. ... I see 7-8 lines output to the tail -f slpipe command, ...
    (perl.beginners)
  • Re: Rename File Using Strring Found in File?
    ... OK, thanks, but the script does not seem to rename the files. ... # sleep 1; ... to the string in this particular file that I want to match. ...
    (comp.lang.perl.misc)
  • Re: How do I implement a delay in VB6
    ... > Try the Sleep API. ... The Sleep() API puts the calling thread to sleep meaning your application is completely unresponsive during the wait, ... Dim StartTime As Double, EndTime As Double ...
    (microsoft.public.vb.general.discussion)