Solved

How to test for a valid mapped drive

Posted on 2002-05-14
2
156 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
Hide vba in gp 7 106
clicking a shape in a frame array vb6 3 47
Publisher:   Unknown     VB.exe Application 1 28
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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