Consulting

Results 1 to 6 of 6

Thread: Disconnected Drive

  1. #1

    Disconnected Drive

    I have a drive mapped to a location that is only available via vpn, the rest of the time it is still mapped but disconnected. When I use the FileSystemObject.Drive.IsReady method, it takes it about 30 seconds to return a value if the drive is disconnected. Is there a faster way to tell if a drive has been disconnected?

    Question is also posted at: http://www.xtremevbtalk.com/showthre...23#post1289423
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  2. #2
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    Yeah I know this is lame, but it is a quick and dirty. Se if it will work for you.

    [VBA]
    Public Function CheckForDrive(iDrvToCheck As String) As Boolean
    Dim a As String
    a = Dir(iDrvToCheck)
    If a > "" Then CheckForDrive = True
    End Function
    'tester sub
    Sub LookAtIt()
    If CheckForDrive("Q:\") Then MsgBox "It is there!! Get to work!"
    If CheckForDrive("C:\") Then MsgBox "It is there!! Get to work!"
    End Sub

    [/VBA]

  3. #3
    Not lame Works fine. Sadly, works as slow as fso.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  4. #4
    VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,168
    Location
    Bummer, I was thinking that the fso was trying to fire up a hibernating drive before returning the .IsReady as false.

    Just as another shot in the dark have you tried anything with the vpn itself? Wouldn't the software be running(in memory) if the vpn is active or connected? Could you check the running processes for it?

    I have all kinds of questions and nothing to play with or test on. Such a sad sad state of affairs LOL

  5. #5
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,478
    Location
    Just a thought, but I would guess a timeout is employed while the code tries to connect. Could you use a timer loop, if not found in 5 secs, then move on?
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  6. #6
    I think I have a partial solution going with Shell32. When a drive is disconnected this can tell for sure. It's flaw is that if once you are connected to VPN it's status won't update to connected until the first time you try to access a folder in the drive. So if it says it's connected it's probably true, while if it says it's disconnected, you will still have to verify that by getting a folder and then testing again.

    [vba]Option Explicit

    Public Enum DriveStatus
    Unknown = 0
    Connected = 1
    Disconnected = 2
    End Enum

    Sub Test()
    MsgBox PrelimDriveCheck("G:")
    End Sub

    Public Function PrelimDriveCheck(Optional ByVal driveLetter As String = "C:") As DriveStatus
    Const strCln_c As String = ":"
    Const strConDrv_c As String = "Network Drive"
    Const strDConDrv_c As String = "Disconnected " & strConDrv_c
    'Uses Shell32.dll
    Dim shl As Shell32.Shell
    Dim fldr As Shell32.Folder3
    Dim eRtnVal As DriveStatus
    On Error GoTo Err_Hnd
    If Not CBool(InStrB(driveLetter, strCln_c)) Then
    driveLetter = driveLetter & strCln_c
    End If
    Set shl = New Shell32.Shell
    Set fldr = shl.Namespace(driveLetter)
    If Not fldr Is Nothing Then
    Select Case fldr.Self.Type
    Case strDConDrv_c
    eRtnVal = Disconnected
    Case strConDrv_c
    eRtnVal = Connected
    Case Else
    eRtnVal = Unknown
    End Select
    End If
    Exit_Proc:
    On Error Resume Next
    Set fldr = Nothing
    Set shl = Nothing
    PrelimDriveCheck = eRtnVal
    Exit Function
    Err_Hnd:
    MsgBox Err.Description, vbSystemModal, "Error: " & Err.Number
    Resume Exit_Proc
    End Function
    [/vba]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •