Windows Vista Forums

WScript.dll not working

  1. #1


    Abhishek Guest

    WScript.dll not working

    Hi,

    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.

    Please guide me to put an delay in a VBScript when it is called from some
    exe.
    --
    Abhishek...

      My System SpecsSystem Spec

  2.   


  3. #2


    Richard Mueller [MVP] Guest

    Re: WScript.dll not working


    "Abhishek" <a_l_soni@xxxxxx> wrote in message
    news:E39747CD-28D9-4611-9E92-49175968AF17@xxxxxx

    > Hi,
    >
    > 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.
    >
    > Please guide me to put an delay in a VBScript when it is called from some
    > exe.
    > --
    > Abhishek...
    The Sleep method is a method of the Wscript object. This object is provided
    by the cscript and wscript host programs (at least WSH version 5.1). If the
    VBScript program is not launched with one of these host programs, the object
    (and it's methods) is not available. How does the exe call the VBScript
    program? Can it run the program using a statement similar to:

    cscript //nologo "c:\Scripts\MyProgram.vbs"

    You may need to provide a path to the cscript.exe program. My recollection
    is that InstallShield can run VBScript programs as custom actions, for
    example, but the Wscript object is not available. I don't recall there being
    a solution for this. I believe you just have to get by without.

    --
    Richard Mueller
    MVP Directory Services
    Hilltop Lab - http://www.rlmueller.net
    --



      My System SpecsSystem Spec

  4. #3


    Pegasus [MVP] Guest

    Re: WScript.dll not working


    "Abhishek" <a_l_soni@xxxxxx> wrote in message
    news:E39747CD-28D9-4611-9E92-49175968AF17@xxxxxx

    > Hi,
    >
    > 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.
    >
    > Please guide me to put an delay in a VBScript when it is called from some
    > exe.
    > --
    > Abhishek...
    This probably depends on your .exe file, not the .vbs file. The .exe file
    probably spawns an independent process to run your script and does not wait
    until the script has finished. It's the same with the Run method in VB
    Scripting: You can set a switch that pauses the script until the Run method
    has finished, or you can get the script to continue immediately.



      My System SpecsSystem Spec

  5. #4


    mr_unreliable Guest

    Re: WScript.dll not working

    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)


      My System SpecsSystem Spec


WScript.dll not working
Similar Threads
Thread Forum
Run Wscript x32 on Vista x64 General Discussion
Re: WScript.Sleep for HTA? VB Script
WScript.Echo VB Script
HTA and Wscript.Sleep VB Script
Invoking PowerShell from WScript via COM PowerShell