Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to Translae a Mapped Drive to a UNC Path

How to Translae a Mapped Drive to a UNC Path

Scheduled Pinned Locked Moved C / C++ / MFC
sysadmintutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    Xilin
    wrote on last edited by
    #1

    When I browse a file under a share folder in server, if the folder is a mapped drive in my computer. I will get the file path like Z:\\abc.dll, how can I translate it to a UNC path like \\\Server\\Open\\abc.dll. Liu Xilin

    S 1 Reply Last reply
    0
    • X Xilin

      When I browse a file under a share folder in server, if the folder is a mapped drive in my computer. I will get the file path like Z:\\abc.dll, how can I translate it to a UNC path like \\\Server\\Open\\abc.dll. Liu Xilin

      S Offline
      S Offline
      saierdia
      wrote on last edited by
      #2

      following is from msdn : To find the UNC path associated with a mapped network drive letter, follow these steps: 1.Create a module and type the following lines in the Declarations section: Option Explicit ' These represent the possible returns errors from API. Public Const ERROR_BAD_DEVICE = 1200& Public Const ERROR_CONNECTION_UNAVAIL = 1201& Public Const ERROR_EXTENDED_ERROR = 1208& Public Const ERROR_MORE_DATA = 234 Public Const ERROR_NOT_SUPPORTED = 50& Public Const ERROR_NO_NET_OR_BAD_PATH = 1203& Public Const ERROR_NO_NETWORK = 1222& Public Const ERROR_NOT_CONNECTED = 2250& Public Const NO_ERROR = 0 ' This API declaration is used to return the ' UNC path from a drive letter. Declare Function WNetGetConnection Lib "mpr.dll" Alias _ "WNetGetConnectionA" _ (ByVal lpszLocalName As String, _ ByVal lpszRemoteName As String, _ cbRemoteName As Long) As Long 2.Type the following procedure: Function GetUNCPath(strDriveLetter As String) As String On Local Error GoTo GetUNCPath_Err Dim Msg As String, lngReturn As Long Dim lpszLocalName As String Dim lpszRemoteName As String Dim cbRemoteName As Long lpszLocalName = strDriveLetter lpszRemoteName = String$(255, Chr$(32)) cbRemoteName = Len(lpszRemoteName) lngReturn = WNetGetConnection(lpszLocalName, _ lpszRemoteName, _ cbRemoteName) Select Case lngReturn Case ERROR_BAD_DEVICE Msg = "Error: Bad Device" Case ERROR_CONNECTION_UNAVAIL Msg = "Error: Connection Un-Available" Case ERROR_EXTENDED_ERROR Msg = "Error: Extended Error" Case ERROR_MORE_DATA Msg = "Error: More Data" Case ERROR_NOT_SUPPORTED Msg = "Error: Feature not Supported" Case ERROR_NO_NET_OR_BAD_PATH Msg = "Error: No Network Available or Bad Path" Case ERROR_NO_NETWORK Msg = "Error: No Network Available" Case ERROR_NOT_CONNECTED Msg = "Error: Not Connected" Case NO_ERROR ' all is successful... End Select If Len(Msg) Then MsgBox Msg, v

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups