Loop for only 10 cycles

From: stev379 (stev379_at_discussions.microsoft.com)
Date: 11/14/04


Date: Sun, 14 Nov 2004 08:16:01 -0800

The script below works great for mapping over a VPN and uses an .htm page to
mask the users password and pull their private directory name from their
username. I'm concerned that it will get caught in a never ending loop when
it's mapping the drives if it's unable to find the drive. I've tested this
by removing the share for the first drive it's trying to map and it doesn't
error out or map anything. I'd like it to loop X (10 if possible) amount of
times before moving on if it can't find the drive. Any suggestions on how
to prevent the loop from going more than 10 cycles?
Any help or suggestions are greatly appreciated!
Thanks!
-Steve

'Begin Script
'****ENTER USERNAME AND PASSWORD****
'Option Explicit
On Error Resume Next
Dim strComputer, IE, path, UsrNm, fso, password,_
Drive1, Drive2, Drive3, intCounter

path = WScript.ScriptFullName
path = Left(path, InstrRev(path, "\"))
intCounter = 1

Set IE = WScript.CreateObject("InternetExplorer.Application")
IE.left=0 'Line 10
IE.top = 50
IE.height = 308
IE.width = 651
IE.menubar = 0
IE.toolbar = 0
IE.statusbar = 0
IE.resizable = 1
IE.navigate path + "WebIn2VB.htm"
IE.visible = 1

Do While (IE.Document.All.OKClicked.Value = "")
  If err <> 0 Then
  Msgbox "Name and Password not entered. "_
  & "Network Drives have not been mapped."
  Set IE = Nothing
  WScript.Quit
  Else
  WScript.Sleep 250
  End If
Loop

' Line 30
UsrNm = IE.Document.All.UsrNm.Value
password = IE.Document.All.PasswordBox.Value
IE.Quit
Set IE = Nothing

Wscript.Sleep 5000
'****BEGIN DRIVE MAPPING****
strMyName = UsrNm
strMyPwd = password
Dim WSHNetwork, objNet
Set WSHNetwork = WScript.CreateObject("WScript.Network")

'strMyName is pulled from UsrNm
strMap2 = "DATA"
strMap3 = "SDP"

strDrv1 = "\\SERVER\" & strMyName
strDrv2 = "\\SERVER\" & strMap2
strDrv3 = "\\SERVER\" & strMap3 'Line 50

StrNet = "DOMAIN\" & strMyName

Drive1 = "P"
Drive2 = "Q"
Drive3 = "R"

Set fso = CreateObject("Scripting.FileSystemObject")

 Do Until fso.DriveExists(Drive1)
WSHNetwork.MapNetworkDrive "P:", strDrv1,"false", strNet, strMyPwd
  If fso.DriveExists(Drive1) Then Exit Do
 Loop

 Do Until fso.DriveExists(Drive2)
WSHNetwork.MapNetworkDrive "Q:", strDrv2, "false", strNet, strMyPwd
  If fso.DriveExists(Drive2) Then Exit Do
 Loop

 Do Until fso.DriveExists(Drive3)
WSHNetwork.MapNetworkDrive "R:", strDrv3,"false", strNet, strMyPwd
  If fso.DriveExists(Drive3) Then Exit Do
 Loop

'****CHECKS IF ALL DRIVES ARE MAPPED AND RETURNS MESSAGE IF NOT****

Dim WshShell, Result
'Wscript.Sleep 5000

On Error Resume Next
set WshShell = CreateObject("WScript.Shell")

If fso.DriveExists(Drive1) Then
 QDRIVE
  Else
Wscript.Echo "P: drive mapping failed"
 QDRIVE
End If

Sub QDRIVE
If fso.DriveExists(Drive2) Then
 RDRIVE
  Else
Wscript.Echo "Q: drive mapping failed"
 RDRIVE
End If
End Sub

Sub RDRIVE
If fso.DriveExists(Drive3) Then
DONE
Else
Wscript.Echo "R: drive mapping failed"
Wscript.quit
End If
End Sub

Sub DONE
Wscript.sleep 2000
Result = WshShell.Popup("Your Mapped drives are now"_
 &" available.", 5,"ASHP Mid-Year Drive Mapping", 0 + 48)
End Sub

'End Script



Relevant Pages

  • Re: Loop for only 10 cycles
    ... I will not comment on other issues, but altered your script ... I'm concerned that it will get caught in a never ending loop ... > Drive, intDrive, intTry, intTryMax ... > Sub QDRIVE ...
    (microsoft.public.windows.server.scripting)
  • Re: Logon Drive Mapping script
    ... >> This script will remap to the correct drive. ... > But a workaround is to add the sub-routine AdjustDriveDescription ... > drives, make a callout to the sub like this: ... > Sub AdjustDriveDescription ...
    (microsoft.public.windows.server.scripting)
  • Re: Syntax Problem...
    ... >> I'm tring to write a script that verifies if the time of the last ... sub Check_Mod ... But it runs in an infinite loop that I would only like to run every 60 ... Do I have the sleep function in the correct place, ...
    (comp.lang.perl.misc)
  • Some help with errors
    ... I have the following script, which reads line by line from a text ... and goes out to find the freespace for the logical drives on ... pctFreeSpace = intFreeSpace / intTotalSpace ... I get a loop without do error, but there is a Do up above. ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem: USB drive letter auto assignment on insert
    ... As promised I made the script and posted it here for others to use. ... modify it to work under Windows 2000 please go ahead and post the mods here. ... Sub SINK_OnObjectReady ... If you want to select drives you can use: ...
    (microsoft.public.windows.server.scripting)