> I am trying to put a delay of 5 seconds in my VBScript using WScript.Sleep
> 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.
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
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.
You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)