Announcement

Collapse
No announcement yet.

Drive Check Error

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Drive Check Error

    Ok, this is a piece of my script I am trying to get through. My problem is for some reason when this script runs the DriveCheck subroutine fails to see my K: Drive on the first run. Once the K: Drive maps and you run this script again it will see the K: Drive.

    This is a problem because users are logging into this drive over a WAN and I need to make it user friendly so I came up with an idea to verify if the drive has mapped so in the case the user put in a bad username or password it will prompt the user to retry. Because the script on the first run can't see the K: Drive after it just mapped it errors out even though it really mapped. Run the script again and it will see the drive. GRRRRRR Well here it is. You also need a third party DLL to get the password box that I found here:

    http://internet.cybermesa.com/~bstewart/passdlg/

    Any Ideas?
    Thanks!!


    Code:
    On Error Resume Next
    Dim intDrive
    Dim CheckDrive
    Dim WshNetwork
    Dim sDriveLetter
    Dim AlreadyConnected
    Dim objPassDlg
    Dim sLabel
    Dim objShell
    Dim strMessage
    Dim MessageBox
    Set WshNetwork = WScript.CreateObject("WScript.Network")
    Set CheckDrive = WshNetwork.EnumNetworkDrives
    Set objPassDlg = CreateObject("PassDlg.LogonDialog")
    Set objShell = CreateObject("Shell.Application")
    
     sDriveLetter = "K:"
     sLabel = "AUM Common"
     
    strMessage = MsgBox("Will you need AUM's Common Drive Today?   ", 36, "Welcome To AWA DET")
      If strMessage = 7 Then WScript.Quit
     	objPassDlg.Confirm = True
     	objPassDlg.ShowDialog "Connecting to AUM's Common Drive"
      If objPassDlg.Canceled Then
    	'Wscript.Echo "Cancelled"
    	wscript.quit
      Else
     	WshNetwork.MapNetworkDrive "K:", "\\xxx.xxx.xxx.xxx\Common", False, objPassDlg.UserName, objPassDlg.Password
     	objShell.NameSpace(sDriveLetter).Self.Name = sLabel
     	WScript.Sleep (5000)
      End If
    
    Call DriveCheck
    
    Sub DriveCheck
     For intDrive = 0 To CheckDrive.Count - 1 Step 2 
      If CheckDrive.Item(intDrive) = sDriveLetter _
      	Then AlreadyConnected = True
      	Next
      If AlreadyConnected = True Then
       	MsgBox "Drive Mapping Successfull!" & vbCrLf & vbCrLf & "Welcome to AUM's Common Drive." _
       	,64,"Connecting to AUM's Common Drive"
       	WScript.Quit
      Else 
      	MessageBox = MsgBox ("Drive Mapping Unsuccessfull" & vbCrLf & vbCrLf & _
      	"Please check your password and make sure your username is as follows.   " _
        & vbCrLf & vbCrLf & "Example: aisinworld\username",21,"Connecting to AUM's Common Drive") 
     End If
    End Sub
    Last edited by Dumber; 27th September 2007, 13:05. Reason: wrapped Codetags arround the script.

  • #2
    Re: Drive Check Error

    Actualy a quit simple answer:

    You create the object 'CheckDrive' to early
    the line
    Set CheckDrive = WshNetwork.EnumNetworkDrives
    Is done before the creation of the new mapping.


    A few adjustments:

    first,
    after you set sDriveLetter = "K:"
    you can replace" K:" in every next line in sDriveLetter (see the line below)
    Code:
    WshNetwork.MapNetworkDrive sDriveLetter, _
                             "\\xxx.xxx.xxx.xxx\Common", _
                             False, objPassDlg.UserName, objPassDlg.Password
    -
    Call the subroutine like this (just to make the script more clear in this case):
    Code:
    Call DriveCheck(sDriveLetter)
    -
    The SubRountine uses its own "Set CheckDrive =" (so you can skip that line in the main part):
    Code:
    Sub DriveCheck(sDriveLetter)
      Set CheckDrive = WshNetwork.EnumNetworkDrives
      For intDrive = 0 To CheckDrive.Count - 1 Step 2 
        If CheckDrive.Item(intDrive) = UCase(sDriveLetter) Then _
          AlreadyConnected = True
      Next
      If AlreadyConnected = True Then
        CreateObject("Wscript.Shell").popup _
          "Drive Mapping Successfull!" & vbCrLf & vbCrLf _
          & "Welcome to AUM's Common Drive." , _
          3, "Connecting to AUM's Common Drive",64
        WScript.Quit
      Else 
        MessageBox = MsgBox ("Drive Mapping Unsuccessfull" & vbCrLf _
        & vbCrLf & "Please check your password and " _
        & "make sure your username is as follows. " & vbCrLf _
        & vbCrLf & "Example: aisinworld\username", _
        21,"Connecting to AUM's Common Drive") 
      End If
    End Sub
    ps-
    can you place your sample code between [CODE]...[/CODE]
    You can do this by selecting the text and click on the # button.


    \Rems
    Last edited by Rems; 26th September 2007, 18:53. Reason: added a UCase() function in the subroutine

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Drive Check Error

      I can't believe I didn’t see that!! lol thanks alot for pointing that out. I learned alot here. I knew it had to be something I was missing. Looks like its going to work like a champ now.

      Thanks alot man!!!!!!

      This message board is a great tool for noobs!!!!!

      Comment

      Working...
      X