Question about looping a script  
Author Message
ChrisNott





PostPosted: Thu Jan 25 08:36:38 CST 2007 Top

VB Scripts >> Question about looping a script

Hi,

I'm using the below script to map a drive:

======
Dim objNetwork

Set objNetwork = CreateObject("Wscript.Network")
On Error Resume Next

objNetwork.RemoveNetworkDrive "G:"
objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
======

What I'd like to do is put in a loop command so it if it fails to map the G
drive (ie, the share isn't available at that time) it keeps trying until it
is successful. I'd also like to set this loop to time out after 5mins if
that's possible?

Could someone show me how this is done?

Thanks,

Curtis.

--
Please reply to news group only. Thank you.

Visual Studio210  
 
 
Ayush





PostPosted: Thu Jan 25 08:36:38 CST 2007 Top

VB Scripts >> Question about looping a script Replied to [Curtis Fray]s message :
> Hi,
>
> I'm using the below script to map a drive:
>
> ======
> Dim objNetwork
>
> Set objNetwork = CreateObject("Wscript.Network")
> On Error Resume Next
>
> objNetwork.RemoveNetworkDrive "G:"
> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> ======
>
> What I'd like to do is put in a loop command so it if it fails to map the G
> drive (ie, the share isn't available at that time) it keeps trying until it
> is successful. I'd also like to set this loop to time out after 5mins if
> that's possible?
>
> Could someone show me how this is done?
>

======
Dim objNetwork

Set objNetwork = CreateObject("Wscript.Network")
On Error Resume Next
objNetwork.RemoveNetworkDrive "G:"
countr = 0
Do Until countr=300000
objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
Wscript.Sleep 1000 'Pause Script for 1 second
countr = countr + 1
Loop

======



--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------
 
 
Curtis





PostPosted: Thu Jan 25 09:29:55 CST 2007 Top

VB Scripts >> Question about looping a script Thanks for the quick reply Ayush.

One other thing, is it possible to put in a further condition so if during
the loop it finds the G Drive has now mapped, it continues with the script
rather than looping until the 5 minutes are up?

Curtis.

==



> Replied to [Curtis Fray]s message :
>> Hi,
>>
>> I'm using the below script to map a drive:
>>
>> ======
>> Dim objNetwork
>>
>> Set objNetwork = CreateObject("Wscript.Network")
>> On Error Resume Next
>>
>> objNetwork.RemoveNetworkDrive "G:"
>> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
>> ======
>>
>> What I'd like to do is put in a loop command so it if it fails to map the
>> G drive (ie, the share isn't available at that time) it keeps trying
>> until it is successful. I'd also like to set this loop to time out after
>> 5mins if that's possible?
>>
>> Could someone show me how this is done?
>>
>
> ======
> Dim objNetwork
>
> Set objNetwork = CreateObject("Wscript.Network")
> On Error Resume Next
> objNetwork.RemoveNetworkDrive "G:"
> countr = 0
> Do Until countr=300000
> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> Wscript.Sleep 1000 'Pause Script for 1 second
> countr = countr + 1
> Loop
>
> ======
>
>
>
> --
> ? Ayush
> -------------
> Search - www.Google.com | Wikipedia - http://en.wikipedia.org
> Snip your long urls - http://snipurl.com/
> -------------


 
 
Tom





PostPosted: Thu Jan 25 09:53:48 CST 2007 Top

VB Scripts >> Question about looping a script
> Hi,
>
> I'm using the below script to map a drive:
>
> ======
> Dim objNetwork
>
> Set objNetwork = CreateObject("Wscript.Network")
> On Error Resume Next
>
> objNetwork.RemoveNetworkDrive "G:"
> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> ======
>
> What I'd like to do is put in a loop command so it if it fails to map the G
> drive (ie, the share isn't available at that time) it keeps trying until it
> is successful. I'd also like to set this loop to time out after 5mins if
> that's possible?
>
> Could someone show me how this is done?
>
> Thanks,
>
> Curtis.
>
> --
> Please reply to news group only. Thank you.

Try something like...

Dim objNetwork, nTime
Const nTimeout = 300000 ' 5 minutes
Const nRetryPause = 5000 ' 5 seconds

Set objNetwork = CreateObject("Wscript.Network")
On Error Resume Next

Do
objNetwork.RemoveNetworkDrive "G:"
objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
if Err.Number <> 0 then
wsh.sleep nRetryPause
nTime = nTime + nRetryPause
Loop until (Err.Number = 0) or nTime => nTimeout

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

 
 
Curtis





PostPosted: Thu Jan 25 10:15:16 CST 2007 Top

VB Scripts >> Question about looping a script Hi Tom,

Thanks for the suggestion. I've tried it but get an error saying:

'loop' without 'do'

Any thoughts?

Thanks,

Curtis.

==



>> Please reply to news group only. Thank you.
>
> Try something like...
>
> Dim objNetwork, nTime
> Const nTimeout = 300000 ' 5 minutes
> Const nRetryPause = 5000 ' 5 seconds
>
> Set objNetwork = CreateObject("Wscript.Network")
> On Error Resume Next
>
> Do
> objNetwork.RemoveNetworkDrive "G:"
> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> if Err.Number <> 0 then
> wsh.sleep nRetryPause
> nTime = nTime + nRetryPause
> Loop until (Err.Number = 0) or nTime => nTimeout
>
> Tom Lavedas
> ===========
> http://members.cox.net/tglbatch/wsh/
>


 
 
Tom





PostPosted: Thu Jan 25 12:21:01 CST 2007 Top

VB Scripts >> Question about looping a script A missing End if on the line before the loop statement.

Tom Lavedas
===========


> Hi Tom,
>
> Thanks for the suggestion. I've tried it but get an error saying:
>
> 'loop' without 'do'
>
> Any thoughts?
>
> Thanks,
>
> Curtis.
>

>

> >> Please reply to news group only. Thank you.
>
> > Try something like...
>
> > Dim objNetwork, nTime
> > Const nTimeout = 300000 ' 5 minutes
> > Const nRetryPause = 5000 ' 5 seconds
>
> > Set objNetwork = CreateObject("Wscript.Network")
> > On Error Resume Next
>
> > Do
> > objNetwork.RemoveNetworkDrive "G:"
> > objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> > if Err.Number <> 0 then
> > wsh.sleep nRetryPause
> > nTime = nTime + nRetryPause

end if ' this is the missing line.

> > Loop until (Err.Number = 0) or nTime => nTimeout
>
> > Tom Lavedas
> > ===========
> >http://members.cox.net/tglbatch/wsh/

 
 
Curtis





PostPosted: Fri Jan 26 03:24:07 CST 2007 Top

VB Scripts >> Question about looping a script Got it going now. Thanks to you both for your input!

One last hurdle I managed to get over is in order to continue the loop after
the drive had mapped, the Err.Number had to equal "-2147024811". A zero
would have been much more logical!! :)

Thanks again.

Kind regards,

Curtis.

==


> Hi,
>
> I'm using the below script to map a drive:
>
> ======
> Dim objNetwork
>
> Set objNetwork = CreateObject("Wscript.Network")
> On Error Resume Next
>
> objNetwork.RemoveNetworkDrive "G:"
> objNetwork.MapNetworkDrive "G:", "\\domain1dc1\test"
> ======
>
> What I'd like to do is put in a loop command so it if it fails to map the
> G drive (ie, the share isn't available at that time) it keeps trying until
> it is successful. I'd also like to set this loop to time out after 5mins
> if that's possible?
>
> Could someone show me how this is done?
>
> Thanks,
>
> Curtis.
>
> --
> Please reply to news group only. Thank you.
>