Solved

How to test for a valid mapped drive

Posted on 2002-05-14
2
154 Views
Last Modified: 2008-03-06
I have an applicaiton that relys on connectivity via mapped
drives to about 5 PC's.
Could you show me the code that would test those
connections to see if they are "live"?

Please note, the code cannot just detect the
existance of a mapped drive, because even if
they log off or shut the PC down, my app's PC could
still be mapped.

I need to know if the mapped drive is still valid.

Example code please ?
0
Comment
Question by:rbend
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 50 total points
ID: 7008253
You can use the following example to get all logical drives and some information about them. Inactive drives will return empty values whereas active ones will return the appropriate information.

Private Declare Function GetLogicalDriveStrings Lib "Kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetVolumeInformation Lib "Kernel32" Alias "GetVolumeInformationA" (ByVal lpRootPathName As String, ByVal lpVolumeNameBuffer As String, ByVal nVolumeNameSize As Long, lpVolumeSerialNumber As Long, lpMaximumComponentLength As Long, lpFileSystemFlags As Long, ByVal lpFileSystemNameBuffer As String, ByVal nFileSystemNameSize As Long) As Long
Private Sub Form_Load()
    Dim strSave As String
    Me.AutoRedraw = True
    strSave = String(255, Chr$(0))
    ret& = GetLogicalDriveStrings(255, strSave)
    For keer = 1 To 100
        If Left$(strSave, InStr(1, strSave, Chr$(0))) = Chr$(0) Then Exit For
        Me.Print Left$(strSave, InStr(1, strSave, Chr$(0)) - 1), IsActive(Left$(strSave, InStr(1, strSave, Chr$(0)) - 1))
        strSave = Right$(strSave, Len(strSave) - InStr(1, strSave, Chr$(0)))
    Next keer
End Sub


Private Function IsActive(ByVal DriveLetter As String) As String
    Dim Serial As Long, VName As String, FSName As String
    VName = String$(255, Chr$(0))
    FSName = String$(255, Chr$(0))
    GetVolumeInformation DriveLetter, VName, 255, Serial, 0, 0, FSName, 255
    VName = Left$(VName, InStr(1, VName, Chr$(0)) - 1)
    FSName = Left$(FSName, InStr(1, FSName, Chr$(0)) - 1)
    IsActive = VName & " : " & FSName & " / " & Trim(Str(Serial))
End Function
0
 

Author Comment

by:rbend
ID: 7008613
This is the ticket !
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now