• UNC Path & Mapped drive (Access 97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » UNC Path & Mapped drive (Access 97 SR2)

    Author
    Topic
    #372189

    Hi Everyone!

    I’m trying to find code (an api call?) that will tell you where a unc path is mapped to.

    I was able to find the api call that tells you what is the unc path of a mapped drive, but I’m looking for exactly the opposite (since the user could easily map a path to a different drive letter).

    Does anyone know where I can find such a thing? I’ve been looking through allapi.net, but haven’t seen this (or at least couldn’t recognize it).

    Any hints would be greatly appreciated.

    Thanks!

    Cecilia 🙂

    Viewing 1 reply thread
    Author
    Replies
    • #594166

      I’m sure somebody will come up with a better idea, but here is a brute force approach.

      You might loop through all drive letters, get the UNC path from it and compare it to “your” UNC path. If you get a match, you know the drive letter and you can exit from the loop. Be sure to convert everything to upper case before comparing.

      • #594175

        Urrrrgh. I hadn’t thought of that, but….

        We have every drive letter mapped and then some. But that’s not really the problem, part of it is that if you do a lot of travelling, or cross-divisional work (like I do), you might have drives mapped that are 3,000 miles away across a 28.8b (or less) Wan. I’ll try it, but I’m worried that between the number of drives mapped and the potential for getting bogged down on the Wan, it’ll be really slow.

        I’m hoping there’s a neater way to do it.

    • #594381

      A UNC path is to network location and eliminates the need for a drive map. Drive mappings depend on the specific domain and can vary between machines. I don’t see how you would ever know how drives were mapped except from the current workstation. What are you actually trying to accomplish with this?

      • #594469

        Hi Charlotte–

        I think I was going overboard with helping out the users. The problem is that some of us map our drives to different letters because we move around between regions and divisions. But most don’t, and don’t know how, and don’t even what a UNC path is. So in order for things to go correctly, I need to use the unc path, but a user wouldn’t know what that is, they’d think it was jibberish. So I wanted to return to the user the equivalent of where things were being saved, in a manner that he’d understand.

        Instead of going through all that, I’ll probably just tell some “superusers” how to do it and let the others go to them for help changing drive paths.

        Cecilia 🙂

        • #601422

          Hi Cecilia,
          This may be a bit late but I came across the WNetGetConnection API this morning and had a vague recollection that someone here had been looking for something like it. I think it should do exactly what you were after.
          Hope that helps.

          • #601574

            Hi Rory!

            LOL, yeah, that project is so far off my desk, I’m not going back….but I’m the same way, a problem is something that _just_ has to be solved.

            I think that is the API call that I use to get the unc path of a mapped drive. But I was trying to do the opposite: get the mapped drive name of a unc path. Is there a way to do that with this call?

            Please don’t spend any time or effort on this, because I won’t use it, but it would be interesting to know….

            Cecilia 🙂

            • #601600

              You wrote:
              I think that is the API call that I use to get the unc path of a mapped drive. But I was trying to do the opposite: get the mapped drive name of a unc path. Is there a way to do that with this call?

              I doubt there is such a thing. This would seemingly imply that there was something fixed about a specific mapping. Since every system could be mapped differently, and since any particular UNC you have might not be mapped at all on a particular PC, the only way to get this is to examine each drive letter yourself.

            • #601612

              If using VB/VBA 6.0 or later you can use File System Object to get mapped network drive for a specified UNC path. You have to set a reference to Microsoft Scripting Runtime library (SCRRUN.DLL). Sample code:

              Sub GetMappedDrive(strUNCPath As String)

              Dim fso As Scripting.FileSystemObject
              Dim D As Scripting.Drive
              Dim bFound As Boolean
              Dim strMsg As String

              bFound = False
              Set fso = CreateObject(“scripting.filesystemobject”)
              For Each D In fso.Drives
              If D.ShareName = strUNCPath Then
              strMsg = “The mapped network drive for UNC path ” & strUNCPath & ” is ” & D.DriveLetter & “:”
              MsgBox strMsg, vbInformation, “MAPPED DRIVE FOUND”
              bFound = True
              End If
              Next D

              If bFound = False Then
              strMsg = “Mapped drive for UNC path ” & strUNCPath & ” not found.”
              MsgBox strMsg, vbInformation, “MAPPED DRIVE NOT FOUND”
              End If

              Set D = Nothing
              Set fso = Nothing

              End Sub

              You can also do the opposite, get UNC path for mapped drive using the Drive object’s ShareName property.

              HTH

            • #601993

              Cool! Now I need a new place to use it 🙂

              Thanks for your help 🙂

            • #629703

              Ugggh, I am back to needing to do this again. Unfortunately, now that we’re in XP, this code doesn’t work (not quite sure why yet). When I try to run it with my network path, it returns the same network path.

              Access 2002, WinXP (for better or worse….)

              Just to set it up again, I have a program that saves documents in a location that the user specifies. When it opens, it opens defaulted to their My Documents folder–Which under XP, is a network path. The users get all scared when they see the network path, since they just want to save it to C:My Documents (or their shared drive, which is s:foldername, which also shows up as a funky network path).

              I need to convert the network path to the drive path. It doesn’t matter if everyone has different drive mappings, because it is only good for saving one document. But I want to convert s112reg3456username$My Documents to simply c:My Documents.

              Does anyone know a way to do this?

              TIA!

              Cecilia 🙂

    Viewing 1 reply thread
    Reply To: UNC Path & Mapped drive (Access 97 SR2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: