Converting Mapped Drives

Emily once commented with a nifty procedure for enumerating mapped drives. It uses the Windows Script Host Object Model. I created a function to convert mapped drives to UNC paths for an application I’m working on.

Public Function ConvertMapped(ByVal sPath As String) As String
    Dim wsNet As WshNetwork
    Dim wsDrives As WshCollection
    Dim i As Long
    Dim sReturn As String
    Set wsNet = New WshNetwork
    Set wsDrives = wsNet.EnumNetworkDrives
    sReturn = sPath
    For i = 0 To wsDrives.Count – 1
        If Left$(sPath, 2) = wsDrives.Item(i) Then
            sReturn = Replace(sPath, wsDrives.Item(i), wsDrives.Item(i + 1), 1, 1)
            Exit For
        End If
    Next i
    ConvertMapped = sReturn
End Function

But I still have a problem. I have a list of documents and a list of links. The user can add a link by navigating to the document (using GetOpenFileName). If the document already exists in the Document table, the link is created. If not, a record is added to the Document table, then the link is created. I need to ensure there are no duplicates in the Document table.

I thought that converting paths to UNC paths would do it, but not so. The user can navigate to a document through multiple network shares. For instance, he could go to \ActserverAIMUSAMydoc.pdf or he could go to \ActserverAllCompaniesAIMUSAMydoc.pdf and he would be pointing to the same document. The paths don’t match, though, so this document could be added twice.

There’s only currently a few of these overlapping shares, so I could catch them “manually” in the code. That doesn’t seem like a good long term solution, though, as certainly another share will crop up that breaks it. Ideas?

Posted in Uncategorized

2 thoughts on “Converting Mapped Drives

  1. So the directory \ActserverAllCompaniesAIMUSA is mounted as \ActserverAIMUSA?

    I suspect you’re going to need to check whether top-level directories on each server are mount points by checking the standard output of

    mountvol \ActserverAIMUSA /L

    where \ActserverAIMUSA could be any top-level directory (AIMUSA) on any server (Actserver). Maybe there are Windows API calls to do this, but I’ve never tried to find out.

  2. THANK YOU!!!!!!!!!!!!!!!!

    This code solved a major headache I was having thanks to
    Access 2007’s OLE integration with Word 2007 not working
    with mapped network drives

    :) :) :) :) :) :)

Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.