Re: Loop for only 10 cycles

From: Roger Abell [MVP] (mvpNoSpam_at_asu.edu)
Date: 11/14/04


Date: Sun, 14 Nov 2004 16:26:52 -0700

I will not comment on other issues, but altered your script
for the main question you posted

-- 
Roger Abell
Microsoft MVP (Windows Server System: Security)
MCDBA,  MCSE W2k3+W2k+Nt4
"stev379" <stev379@discussions.microsoft.com> wrote in message 
news:1E55E35C-718D-4F2A-AF46-C71895796AEF@microsoft.com...
> 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,_
> Drive(2), intDrive, intTry, intTryMax
> '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"
> Drive(0) = "P"
> Drive(1) = "Q"
> Drive(2) = "R"
> intTryMax = 10
> intDrive = -1
>
> Set fso = CreateObject("Scripting.FileSystemObject")
>
> Do While intDrive < 2
>    intDrive = intDrive  + 1
>    intTry = 0
>    Do While (intTry < intTryMax) and (not 
> fso.DriveExists(Drive(intDrive)))
>       intTry = intTry + 1
>       WSHNetwork.MapNetworkDrive "P:", strDrv1,"false", strNet, strMyPwd
>    Loop
>    If not fso.DriveExists(Drive(intDrive)) then
>       Wscript.Echo "P: drive mapping failed"
>    End If
> Loop
>
>
> If false Then
>
> 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
>
> End If ' end If false that skips unused code
>
> Sub DONE
> On Error Resume Next
> set WshShell = CreateObject("WScript.Shell")
> 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: 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)
  • Re: reload the vbscript itself within a vbscript
    ... Loop ... >> input is less than 1 character long, the script will reload. ... >> However, the problem is that it is sub procedure, the sInputUserDept is ...
    (microsoft.public.scripting.vbscript)
  • RE: OWA usage analysis script
    ... I'll just keep this script updated on PSC ... > sub processfile ... > Hits Long, TS DateTime)" ...
    (microsoft.public.exchange2000.clients)
  • Loop for only 10 cycles
    ... The script below works great for mapping over a VPN and uses an .htm page to ... 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. ... Sub QDRIVE ...
    (microsoft.public.windows.server.scripting)
  • RE: Email and Fax a Report
    ... Opening a report in a loop seems odd, ... By placing the sub on its own, ... Dim objOutlook As Outlook.Application ... Set newMail = objOutlook.CreateItem ...
    (microsoft.public.access.modulesdaovba)

Quantcast