WScript refuses to sleep(WTF!?) 
Author Message
 WScript refuses to sleep(WTF!?)

No matter what I do, I cannot use the sleep method. This results in much
frustration, as I am
using sendKeys, and the app I am sending to doesn't always get all the
keys that I'm trying to
send. If I run this script by itself as a vbs file, it works fine, but I
need to be able to embed
it in an HTA.

Here's an example:

Dim SW
Dim WScript

Function sendAndWait_thenSendMore()
  Set SW = CreateObject("WScript.Shell")
  SW.AppActivate("Notepad")
  SW.SendKeys "Potatoes are brown outside,"
  WScript.Sleep 1000
  SW.SendKeys " but they are white inside."
  Set SW = nothing
End Function

If I snip out the 'WScript.Sleep 1000' line, all is well. If I leave it
in and try to run the script,
I get "Error: Object required: 'WScript'". Any help in this matter would
be greatly appreciated.



Thu, 05 Aug 2004 10:53:52 GMT  
 WScript refuses to sleep(WTF!?)
The "built in" WScript object is not built in to the browser, it is exists *only* when wscript.exe or cscript.exe hosts the script.

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> No matter what I do, I cannot use the sleep method. This results in much
> frustration, as I am
> using sendKeys, and the app I am sending to doesn't always get all the
> keys that I'm trying to
> send. If I run this script by itself as a vbs file, it works fine, but I
> need to be able to embed
> it in an HTA.

> Here's an example:

> Dim SW
> Dim WScript

> Function sendAndWait_thenSendMore()
>   Set SW = CreateObject("WScript.Shell")
>   SW.AppActivate("Notepad")
>   SW.SendKeys "Potatoes are brown outside,"
>   WScript.Sleep 1000
>   SW.SendKeys " but they are white inside."
>   Set SW = nothing
> End Function

> If I snip out the 'WScript.Sleep 1000' line, all is well. If I leave it
> in and try to run the script,
> I get "Error: Object required: 'WScript'". Any help in this matter would
> be greatly appreciated.



Thu, 05 Aug 2004 09:09:01 GMT  
 WScript refuses to sleep(WTF!?)
So there is absolutely no way to use sleep in an HTA? That totally
sucks:-(
Quote:

> The "built in" WScript object is not built in to the browser, it is exists *only* when wscript.exe or cscript.exe hosts the script.

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> > No matter what I do, I cannot use the sleep method. This results in much
> > frustration, as I am
> > using sendKeys, and the app I am sending to doesn't always get all the
> > keys that I'm trying to
> > send. If I run this script by itself as a vbs file, it works fine, but I
> > need to be able to embed
> > it in an HTA.

> > Here's an example:

> > Dim SW
> > Dim WScript

> > Function sendAndWait_thenSendMore()
> >   Set SW = CreateObject("WScript.Shell")
> >   SW.AppActivate("Notepad")
> >   SW.SendKeys "Potatoes are brown outside,"
> >   WScript.Sleep 1000
> >   SW.SendKeys " but they are white inside."
> >   Set SW = nothing
> > End Function

> > If I snip out the 'WScript.Sleep 1000' line, all is well. If I leave it
> > in and try to run the script,
> > I get "Error: Object required: 'WScript'". Any help in this matter would
> > be greatly appreciated.



Thu, 05 Aug 2004 11:29:09 GMT  
 WScript refuses to sleep(WTF!?)
No, but if you *must* have the equivalent, you could fashion something (rather ugly) out of setTimeout or setInterval or use the free ScriptX component for www.meadroid.com which has a Wait method.

(I'm starting to sound like a pitch man for MeadCo ;-)...

Or to be ***really*** ugly, use wshshell.run to execute a separate wscript.exe hosted script that just does a sleep.  Run with a hidden window (2nd arg 0) and wait for completion (3rd arg True)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Quote:

> So there is absolutely no way to use sleep in an HTA? That totally
> sucks:-(


> > The "built in" WScript object is not built in to the browser, it is exists *only* when wscript.exe or cscript.exe hosts the script.

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > > No matter what I do, I cannot use the sleep method. This results in much
> > > frustration, as I am
> > > using sendKeys, and the app I am sending to doesn't always get all the
> > > keys that I'm trying to
> > > send. If I run this script by itself as a vbs file, it works fine, but I
> > > need to be able to embed
> > > it in an HTA.

> > > Here's an example:

> > > Dim SW
> > > Dim WScript

> > > Function sendAndWait_thenSendMore()
> > >   Set SW = CreateObject("WScript.Shell")
> > >   SW.AppActivate("Notepad")
> > >   SW.SendKeys "Potatoes are brown outside,"
> > >   WScript.Sleep 1000
> > >   SW.SendKeys " but they are white inside."
> > >   Set SW = nothing
> > > End Function

> > > If I snip out the 'WScript.Sleep 1000' line, all is well. If I leave it
> > > in and try to run the script,
> > > I get "Error: Object required: 'WScript'". Any help in this matter would
> > > be greatly appreciated.



Thu, 05 Aug 2004 10:01:24 GMT  
 WScript refuses to sleep(WTF!?)
I've never had the use of Sleep in an HTA, but I think that you can "build" a function that does a pause by using
time relatives functions of VBScript, specially : Now, Second, Minute and the Do...While statement.
This depends of the context of your HTA too.

Perhaps can you find a sample here :
http://cwashington.netreach.net

Jean - JMST
Belgium



Fri, 06 Aug 2004 06:59:04 GMT  
 WScript refuses to sleep(WTF!?)
This will do it, but it tends to be a CPU hog:

  <script language="VBScript" type="text/vbscript">
  <!--
   MsgBox "Let the timing start..."
   t0=timer
   do while timer - t0 < 10:loop
   MsgBox "end time is " & timer & vbCRLF & "start time was " & t0
  //-->
 </script>

Meadroid ScriptX and AutoItX are much nicer, not to mention free.



Quote:
> I've never had the use of Sleep in an HTA, but I think that you can

"build" a function that does a pause by using
Quote:
> time relatives functions of vbscript, specially : Now, Second,

Minute and the Do...While statement.
Quote:
> This depends of the context of your HTA too.

> Perhaps can you find a sample here :
> http://cwashington.netreach.net

> Jean - JMST
> Belgium



Fri, 06 Aug 2004 08:00:40 GMT  
 WScript refuses to sleep(WTF!?)
I've just do a try by using DateDiff vbscript function and seems
to work (interval is in second).

Here is the VBS sub :

Sub Pause(qty)'qty=number of seconds to pause
 Actual=Now
 Do Until DateDiff("s",Actual,Now)=qty
 Loop
End Sub

... and the test inside an HTA ... :

<!---8<---HTA_sample_with_Pause.hta---Cut-Here--->
<head>
<script language="vbscript">
'sendAndWait_thenSendMore
Sub TestPause()
  Set SW = CreateObject("WScript.Shell")
  SW.Run "Notepad"
  Pause(3)
  SW.SendKeys "Potatoes are brown outside,"
  Pause(2)
  SW.SendKeys " but they are white inside."
  Set SW = Nothing
End Sub

Sub Pause(qty)'qty=number of seconds to pause
 Actual=Now
 Do Until DateDiff("s",Actual,Now)=qty
 Loop
End Sub
</script>
</head>
<body>
<input type=button value='Click me to start Notepad and send keys' onclick='TestPause'>
</body>
<!---8<---HTA_sample_with_Pause.hta---Cut-Here--->

Regards,

Jean - JMST
Belgium



Fri, 06 Aug 2004 08:31:47 GMT  
 WScript refuses to sleep(WTF!?)
window.setInterval does the job. See below link where Michael Harris plays.

http://groups.google.com/groups?hl=en&threadm=OJIKwfKZBHA.988%40tkmsf...
rnum=1&prev=/groups%3Fas_q%3Dwhat%2520a%2520magic%26as_ugroup%3Dmicrosoft.pu
blic.scripting.wsh%26as_uauthors%3Dhan%26hl%3Den



Quote:
> This will do it, but it tends to be a CPU hog:

>   <script language="VBScript" type="text/vbscript">
>   <!--
>    MsgBox "Let the timing start..."
>    t0=timer
>    do while timer - t0 < 10:loop
>    MsgBox "end time is " & timer & vbCRLF & "start time was " & t0
>   //-->
>  </script>

> Meadroid ScriptX and AutoItX are much nicer, not to mention free.



> > I've never had the use of Sleep in an HTA, but I think that you can
> "build" a function that does a pause by using
> > time relatives functions of vbscript, specially : Now, Second,
> Minute and the Do...While statement.
> > This depends of the context of your HTA too.

> > Perhaps can you find a sample here :
> > http://cwashington.netreach.net

> > Jean - JMST
> > Belgium



Fri, 06 Aug 2004 08:39:08 GMT  
 WScript refuses to sleep(WTF!?)
Hi Alex,

Yes, there are several possibilities I think.
I don't know which is the best for CPU activity.
It's because Killah speak about VBS but JScript
have some time relatives function too ... I haven't try.
I'm pretty certain this subject was already treated here
some times ago but as I wasn't really interrested at this time I haven't used my red spectacles :-) ...
so ... search - Google ... or Cwashington site.

Just a final note for Gorillah : I think that you really gain
to post your original HTA "code" as in scripting a case
in often not an other case (one need the right way and other the left one).
This is tagged <friendly> :-) of course.

Regards,

Jean - JMST
Belgium



Fri, 06 Aug 2004 08:44:51 GMT  
 WScript refuses to sleep(WTF!?)
Move over Perl...

"There's more than 1 way to do it in IE!"



Quote:
> I've just do a try by using DateDiff vbscript function and seems
> to work (interval is in second).

> Here is the VBS sub :

> Sub Pause(qty)'qty=number of seconds to pause
>  Actual=Now
>  Do Until DateDiff("s",Actual,Now)=qty
>  Loop
> End Sub

> ... and the test inside an HTA ... :

> <!---8<---HTA_sample_with_Pause.hta---Cut-Here--->
> <head>
> <script language="vbscript">
> 'sendAndWait_thenSendMore
> Sub TestPause()
>   Set SW = CreateObject("WScript.Shell")
>   SW.Run "Notepad"
>   Pause(3)
>   SW.SendKeys "Potatoes are brown outside,"
>   Pause(2)
>   SW.SendKeys " but they are white inside."
>   Set SW = Nothing
> End Sub

> Sub Pause(qty)'qty=number of seconds to pause
>  Actual=Now
>  Do Until DateDiff("s",Actual,Now)=qty
>  Loop
> End Sub
> </script>
> </head>
> <body>
> <input type=button value='Click me to start Notepad and send keys'

onclick='TestPause'>

- Show quoted text -

Quote:
> </body>
> <!---8<---HTA_sample_with_Pause.hta---Cut-Here--->

> Regards,

> Jean - JMST
> Belgium



Fri, 06 Aug 2004 08:59:35 GMT  
 WScript refuses to sleep(WTF!?)
Thank you everyone for these most helpful replies:-) I don't know if
you've heard of Rhinoceros3d, but it's the program I'm really trying to
send keys to, to automate building objects. The reason I need sleep is
that sometimes the keys are getting sent before the process has properly
activated, and the remaining, truncated key sequences are naturally not
valid commands/options. I was about to give up completely before I saw
the replies.

Ok, actually I also need sleep because I've been awake too long:-P

Quote:

> Move over Perl...

> "There's more than 1 way to do it in IE!"



> > I've just do a try by using DateDiff vbscript function and seems
> > to work (interval is in second).

> > Here is the VBS sub :

> > Sub Pause(qty)'qty=number of seconds to pause
> >  Actual=Now
> >  Do Until DateDiff("s",Actual,Now)=qty
> >  Loop
> > End Sub

> > ... and the test inside an HTA ... :

> > <!---8<---HTA_sample_with_Pause.hta---Cut-Here--->
> > <head>
> > <script language="vbscript">
> > 'sendAndWait_thenSendMore
> > Sub TestPause()
> >   Set SW = CreateObject("WScript.Shell")
> >   SW.Run "Notepad"
> >   Pause(3)
> >   SW.SendKeys "Potatoes are brown outside,"
> >   Pause(2)
> >   SW.SendKeys " but they are white inside."
> >   Set SW = Nothing
> > End Sub

> > Sub Pause(qty)'qty=number of seconds to pause
> >  Actual=Now
> >  Do Until DateDiff("s",Actual,Now)=qty
> >  Loop
> > End Sub
> > </script>
> > </head>
> > <body>
> > <input type=button value='Click me to start Notepad and send keys'
> onclick='TestPause'>
> > </body>
> > <!---8<---HTA_sample_with_Pause.hta---Cut-Here--->

> > Regards,

> > Jean - JMST
> > Belgium



Fri, 06 Aug 2004 17:24:00 GMT  
 WScript refuses to sleep(WTF!?)
hi Killah,

If you are courageous enough (or fool-hardy enough) to use a third-party
control, then you will find a "sleep" method in Jonathan Bennett's AutoItX.

Also, there is a "sleep" method in Meadroid's ScriptX control. (Meadroid
calls it "Wait").

cheers, jw


Quote:
> No matter what I do, I cannot use the sleep method. This results in much
> frustration, as I am
> using sendKeys, and the app I am sending to doesn't always get all the
> keys that I'm trying to
> send. If I run this script by itself as a vbs file, it works fine, but I
> need to be able to embed
> it in an HTA.

> Here's an example:

> Dim SW
> Dim WScript

> Function sendAndWait_thenSendMore()
>   Set SW = CreateObject("WScript.Shell")
>   SW.AppActivate("Notepad")
>   SW.SendKeys "Potatoes are brown outside,"
>   WScript.Sleep 1000
>   SW.SendKeys " but they are white inside."
>   Set SW = nothing
> End Function

> If I snip out the 'WScript.Sleep 1000' line, all is well. If I leave it
> in and try to run the script,
> I get "Error: Object required: 'WScript'". Any help in this matter would
> be greatly appreciated.



Sat, 07 Aug 2004 03:57:50 GMT  
 WScript refuses to sleep(WTF!?)
For AutoItX and ScriptX it's what Alex said too.
I don't know those controls but I ask me if it's
to use a third party control to do a "sleep", it
should be possible to use the Sleep function of
Kernell32.dll library to build an OCX with VB5CCE.
Something like (approximately):

'--OCX Sleep Sample
Private Declare Sub Sleep Lib "kernel32" (ByVal Millisecond As Long)
Public Sub Wait(qty)
 Sleep qty
End Sub
'--OCX Sleep Sample

I ask me too, as Killah speaks about a 3D app :
1- if this app hasn't macro capacities inside (as it's often the case with this kind
of app).
2-if it's a good idea to use a Sleep way to automate 3D tasks as I think
time process to perform a 3D task could be very fluctuating.

Regards,

Jean - JMST
Belgium



Sat, 07 Aug 2004 09:14:42 GMT  
 WScript refuses to sleep(WTF!?)
Rhino does have built-in scripting (including VBScript), but for what
I'm doing, (a dialog that takes pre-assigned unput and builds things to
size accordingly), I'm not yet good enough to do entirely in VBScript,
plus there are other issues as regards to running a script within the
program or as an entirely seperate process. Another reason I'm asking
questions here is that I'm also interested in learning more about
VBS/WSH in general.
 Also, I was doing something else earlier using an HTA, not 3d-related,
and was wondering why sleep wasn't available. The excellent insight
provided here has saved me a lot of headaches:-)
Quote:

> For AutoItX and ScriptX it's what Alex said too.
> I don't know those controls but I ask me if it's
> to use a third party control to do a "sleep", it
> should be possible to use the Sleep function of
> Kernell32.dll library to build an OCX with VB5CCE.
> Something like (approximately):

> '--OCX Sleep Sample
> Private Declare Sub Sleep Lib "kernel32" (ByVal Millisecond As Long)
> Public Sub Wait(qty)
>  Sleep qty
> End Sub
> '--OCX Sleep Sample

> I ask me too, as Killah speaks about a 3D app :
> 1- if this app hasn't macro capacities inside (as it's often the case with this kind
> of app).
> 2-if it's a good idea to use a Sleep way to automate 3D tasks as I think
> time process to perform a 3D task could be very fluctuating.

> Regards,

> Jean - JMST
> Belgium



Sat, 07 Aug 2004 20:26:40 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. wscript.sleep 1 and wscript.sleep 2

2. Wscript.shell refusing to run a command from an ASP page

3. wscript.sleep does not work

4. wscript.sleep in HTA

5. wscript.sleep does not work

6. Alternative to WScript.Sleep method?

7. wscript.sleep in a custom action

8. WScript.sleep(s) too long?

9. WScript.Sleep error in ASP page

10. wscript.sleep

11. vbs script dies on the WScript.Sleep command

12. WScript.Sleep and HTML

 

 
Powered by phpBB® Forum Software