Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to test for a valid mapped drive

Posted on 2002-05-14
2
Medium Priority
?
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 200 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 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