Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Issues with VB scripts timing out - Can anyone shed some light on this?

1 view
Skip to first unread message

owl

unread,
Jun 14, 2002, 9:37:25 AM6/14/02
to
Hello all:

Just starting my action-packed programming tasks at work and i am
having an issue. trying to a script to run that seems to be timing
out before it reaches the end.

Sample posted here:
'script timeout counter
msgbox "wscript.timeout = " & wscript.timeout
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies
PrimalSCRIPT(TM)
'
' NAME: <mapnet.vbs>
'
' AUTHOR: Renegade
' DATE : 6/12/2002
'
' COMMENT: <Copy Function for GiftMaker Pro data files from Location
of Origin to Back-up Server area.>
'<<<!!!RENAGADE>>>
'==========================================================================
Dim WSHNetwork
Set WSHNetwork = WScript.CreateObject("WScript.Network")

Dim ScriptControl
Set ScriptControl = WScript.CreateObject("WScript.Timeout")

ScriptControl.Timeout [= 40]

Dim DateToday
DateToday = Date

'map selected drives here
WSHNetwork.MapNetworkDrive "T:", "\\server1\TechM1"
WSHNetwork.MapNetworkDrive "U:", "\\server2\Campagne"

'copy files here
Dim FileSystemObject
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
FileSystemObject.CopyFolder "U:\Manuals" , "t:\backup"
MsgBox "Your Files have been copied!"
MsgBox "Today's date is " & DateToday & "."
'MsgBox "Your Network Drives have been mapped!"

'Remove all connected netowkr drives from system here
WSHNetwork.RemoveNetworkDrive "T:"
WSHNetwork.RemoveNetworkDrive "U:"

Before i get to the last two lines i get the following:


Script execution time was exceeded on script "C:\Program
Files\SAPIEN\Primalscript\Samples\mapnet.vbs".
Script execution was terminated.

Can anyone assist in this issue?

Thanks

Renegade

alex_k._angelopoulos_(mvp)

unread,
Jun 14, 2002, 11:14:46 AM6/14/02
to
You have several things in there which could take a while - and the MsgBox
lines, of course, will halt execution while they are popped up. I would suggest
lengthening the timeout significantly.

"owl" <lako...@hotmail.com> wrote in message
news:2urjguc79oufbaj0q...@4ax.com...

Torgeir Bakken

unread,
Jun 14, 2002, 12:16:06 PM6/14/02
to
owl wrote:

> Just starting my action-packed programming tasks at work and i am
> having an issue. trying to a script to run that seems to be timing
> out before it reaches the end.

Try to disable disable timeout by assigning it to 0 and see what happens.

Add this to the top of your script:
wscript.timeout = 0

--
torgeir


owl

unread,
Jun 14, 2002, 1:41:06 PM6/14/02
to
Alex:

Any thoughts on how to do this? I did not add any timeout to this
script, but if you can add any thoughts to this, that would be great.
A bit new to vbscript.

Thanks

Renegade

Torgeir Bakken

unread,
Jun 14, 2002, 1:56:58 PM6/14/02
to
owl wrote:

> Any thoughts on how to do this? I did not add any timeout to this
> script, but if you can add any thoughts to this, that would be great.
> A bit new to vbscript.

In the discussion "Script TIming Out" at
http://cwashington.netreach.net/community/lounge/default.asp

you said that wscript.timeout returned 10.

That means that your timeout is set to 10 seconds permanently.

To disable timeout permanently (globally), run this command from e.g. Start\Run

wscript //t:0 //s


--
torgeir


alex_k._angelopoulos_(mvp)

unread,
Jun 14, 2002, 3:52:29 PM6/14/02
to
That's a neat idea Torgeir - never tried that trick before myself, and it works
quite nicely...
"Torgeir Bakken" <Torgeir.B...@hydro.com> wrote in message
news:3D0A16C6...@hydro.com...

Michael Harris (MVP)

unread,
Jun 14, 2002, 5:30:51 PM6/14/02
to
Alex K. Angelopoulos (MVP) wrote:
> That's a neat idea Torgeir - never tried that trick before myself,
> and it works quite nicely...

I re-post of my treatise on the under-documented Timeout property...

Wscript.Timeout

Here's a (slightly modified) repost of a followup I posted back on 12/21/2000, about a month after WSH 5.6 beta 1 was made available)...

This is a case in point that proves that the WSH dev team monitors and responds to information that is posted in the newsgroup...

Back on July 25, 2000 I posted some details on how the undocumented WScript.Timeout property behaved. One odd aspect was that is was impossible for a script to determine reliably whether or not a timeout had been enabled.

The "problem" (if there can even be a "problem" for an undocumented feature ;-) was that even if no timeout had been enabled in any way, the WScript.Timeout property always had the global default timeout value. This can only have a non-zero value even if global timeouts are NOT enabled. If a //T:nn switch (or a .wsh file) was used to execute the script, then that value (0 or otherwise) would been seen via the Timeout property. The net effect was that if a script saw a non-zero Timeout property value, it did not necessarily mean that a timeout had been enabled.

I decided to test if that behavior had changed and in fact it had. I had never passed what I had found about the Timeout property behavior to the WSH dev team in any way other than that one public post. So this proves that even if a "problem" is not publicly acknowledged, it does not mean it is ignored.

Here's what I have determined about how WScript.Timeout now behaves.

========================================================
WScript.Timeout Property
========================================================

From within executing script code, you have limited control over the timeout. There is a WScript.Timeout property (essentially undocumented) that works only under certain circumstances.

Script timeouts can be enabled or disabled globally for all scripts (run WScript.exe with no arguments to check the "Windows Script Host Settings" dialog). It can also be enabled or disabled on a per script basis by executing the script with an explicit //T:nn host switch. A non-zero value enables timeout and 0 disables it. It can also be enabled/disabled by using a comparable .wsh file setting and executing the script indirectly through the .wsh file.

If a timeout has been enabled using any of the methods described above, WScript.Timeout will have a non-zero value when checked by script code. Changing the Timeout property from script code will have no effect when it initially is non-zero. For example, if the Timeout property initially has a value of 10 and the script changes it to 30 (or any other value) and then checks the Timeout property again, it will still be 10. The script assigned value is *completely* ignored by the host when a timeout is already enabled.

If a timeout has been NOT been enabled (WScript.Timeout is 0), then a script assigned WScript.Timeout will be honored. This is the *only* situation where a script can self impose a timeout on itself. What is most interesting is that any time the script assigns the Timeout property, the timeout period is relative the point at which the value is assigned regardless of how much of any previous timeout (if any) has already been consumed.

So why would a script care about the Timeout property anyway? One very good use is to prevent potentially runaway loops! Prior to entering the loop, a script could dynamically enable a timeout by assigning a reasonable "drop dead" timeout. If the loop exits successfully, then timeout could be disabled by assigning it to 0.

Here's a simple test script that illustrates this new behavior.

================================================


msgbox "wscript.timeout = " & wscript.timeout

wscript.timeout = 5
wscript.sleep 4000

wscript.timeout = 10
msgbox "wscript.timeout is now = " _
& wscript.timeout & vbcrlf & vbcrlf _
& "Even though we burned 4 seconds deliberately " & vbcrlf _
& "this message box will stay up for " _
& "another 10 seconds" & vbcrlf _
& "(check you watch and wait for the timeout " _
& "or click OK to continue)..."

wscript.timeout = 0
msgbox "wscript.timeout is now = " _
& wscript.timeout & vbcrlf & vbcrlf _
& "Since we have now disabled timeout " & vbcrlf _
& "this message box will stay up until closed..."

msgbox "Now we'll set wscript.timeout to 5 " _
& "and deliberately go into" & vbcrlf _
& "a loop that will last LESS than 5 seconds..."

wscript.timeout = 5
for n = 1 to 3: wscript.sleep 1000: next

wscript.timeout = 0
msgbox "Now we'll set wscript.timeout to 5 " _
& "and deliberately go into" & vbcrlf _
& "a loop that will last MORE than 5 seconds..." & vbcrlf _
& "(you'll never see the final messsage)" & vbcrlf

wscript.timeout = 5
for n = 1 to 10: wscript.sleep 1000: next

msgbox "You'll never see this message..."

================================================


--
Michael Harris
Microsoft.MVP.Scripting
Seattle WA US
--


alex_k._angelopoulos_(mvp)

unread,
Jun 14, 2002, 6:05:06 PM6/14/02
to
Interesting.

By the way, I found one interesting thing when playing with your script,
Michael... It looks like if you change the TimeOut property within a script, it
restarts the countdown timer!

"Michael Harris (MVP)" <mik...@mvps.org> wrote in message
news:OX#7nq#ECHA.1424@tkmsftngp04...

Torgeir Bakken

unread,
Jun 14, 2002, 6:09:52 PM6/14/02
to
"Alex K. Angelopoulos (MVP)" wrote:

> By the way, I found one interesting thing when playing with your script,
> Michael... It looks like if you change the TimeOut property within a script, it
> restarts the countdown timer!

Isn't it that Michael says here:

<qoute>


What is most interesting is that any time the script assigns the Timeout property,
the timeout period is relative the point at which the value is assigned regardless

of how much of any previous timeout (if any) has already been consumed.</qoute>

--
torgeir


0 new messages