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.

Re: Question about looping a script by Ayush

Ayush
Thu Jan 25 08:36:38 CST 2007

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/
-------------

Re: Question about looping a script by Curtis

Curtis
Thu Jan 25 09:29:55 CST 2007

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.

==

"Ayush" <"ayushmaan.j[aatt]gmail.com"> wrote in message
news:%239IeK5IQHHA.320@TK2MSFTNGP06.phx.gbl...
> 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/
> -------------



Re: Question about looping a script by Tom

Tom
Thu Jan 25 09:53:48 CST 2007

On Jan 25, 7:32 am, "Curtis Fray" <x...@xxx.com> wrote:
> 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/


Re: Question about looping a script by Curtis

Curtis
Thu Jan 25 10:15:16 CST 2007

Hi Tom,

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

'loop' without 'do'

Any thoughts?

Thanks,

Curtis.

==
"Tom Lavedas" <tglbatch@cox.net> wrote in message
news:1169740428.459117.187290@v45g2000cwv.googlegroups.com...
> On Jan 25, 7:32 am, "Curtis Fray" <x...@xxx.com> wrote:
>> 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/
>



Re: Question about looping a script by Tom

Tom
Thu Jan 25 12:21:01 CST 2007

A missing End if on the line before the loop statement.

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

On Jan 25, 11:15 am, "Curtis Fray" <x...@xxx.com> wrote:
> Hi Tom,
>
> Thanks for the suggestion. I've tried it but get an error saying:
>
> 'loop' without 'do'
>
> Any thoughts?
>
> Thanks,
>
> Curtis.
>
> =="Tom Lavedas" <tglba...@cox.net> wrote in messagenews:1169740428.459117.187290@v45g2000cwv.googlegroups.com...
>
> > On Jan 25, 7:32 am, "Curtis Fray" <x...@xxx.com> wrote:
> >> 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/


Re: Question about looping a script by Curtis

Curtis
Fri Jan 26 03:24:07 CST 2007

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.

==
"Curtis Fray" <xxx@xxx.com> wrote in message
news:uBPGezHQHHA.2312@TK2MSFTNGP04.phx.gbl...
> 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.
>