View Full Version : Disconnected Drive
Oorang
05-28-2008, 02:27 PM
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/showthread.php?p=1289423#post1289423
Tommy
05-30-2008, 11:48 AM
Yeah I know this is lame, but it is a quick and dirty. Se if it will work for you. :)
 
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
Oorang
05-30-2008, 01:00 PM
Not lame :) Works fine. Sadly, works as slow as fso.
Tommy
05-30-2008, 02:52 PM
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
mdmackillop
06-01-2008, 02:30 AM
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?
Oorang
06-01-2008, 09:56 AM
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.
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
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.