Results 1 to 12 of 12

Thread: Convert UNC Path to local Drive and path

  1. #1

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Convert UNC Path to local Drive and path

    I thought there was a way to do this but I can't remember it. Ho can you convert a UNC path back to a local drive and path (mapped or local). I believe there was an API but I can't find it.

    ex. \\server\development converts to Z:\Development

  2. #2
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Convert UNC Path to local Drive and path

    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  3. #3

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Convert UNC Path to local Drive and path

    That does exactly the OPPOSITE of what I asked for...???

  4. #4
    No place like 127.0.0.1 eyeRmonkey's Avatar
    Join Date
    Jul 2005
    Location
    Blissful Oblivion
    Posts
    2,306

    Re: Convert UNC Path to local Drive and path

    Sorry.

    How about one of these:
    http://vbnet.mvps.org/index.html?cod...ndfilename.htm
    http://vbnet.mvps.org/index.html?cod...umresource.htm

    I didn't read closely on the first one and these 2 I am somewhat guessing.
    Visual Studio 2005 Professional Edition (.NET Framework 2.0)
    ~ VB .NET Links: Visual Basic 6 to .NET Function Equivalents (Thread) | Refactor! (White Paper) | Easy Control for Wizard Forms | Making A Proper UI For WinForms | Graphics & GDI+ Tutorial | Websites For Free Icons
    ~ QUOTE: Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. -Rich Cook

    ~ eyeRmonkey.com

  5. #5
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Convert UNC Path to local Drive and path


  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Convert UNC Path to local Drive and path

    I think I know what Randem wants, something like a reverse share translation. If you have a remote share folder, translate that into the remote systems logical path.

    \\servername\sharename <-> C:\Somefolder\sharedfoldername

    I have this code in one of my programs. It may take a bit for me to find it cause it may be in sourcesafe. Be back.
    Last edited by RobDog888; Nov 15th, 2005 at 12:40 AM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Convert UNC Path to local Drive and path

    Too much editng to make an example from my program. I did find the APIs needed which lead me to find an easy example on allapi.net.

    Example Source

    VB Code:
    1. 'This example was submitted by Lee Carpenter
    2. '
    3. 'It needs a class module and a form, with a label (m_lblStatus) on the form
    4.  
    5. 'In the class module (CprgNetShareGetInfo)
    6.  
    7. Option Explicit
    8.  
    9. 'local variable(s) to hold property value(s)
    10. Private mvarstrServer As Variant 'local copy
    11. Private mvarstrNetName As Variant 'local copy
    12. Private mvarnType As Long 'local copy
    13. Private mvarstrRemark As Variant 'local copy
    14. Private mvarnCurrent_uses As Long 'local copy
    15. Private mvarnMax_uses As Long 'local copy
    16. Private mvarstrPath As Variant 'local copy
    17. Private mvarnLastError As Long 'local copy
    18. Private mvarstrLastError As Variant 'local copy
    19. Private mvarNET_API_STATUS As Long 'local copy
    20.  
    21. 'local variable(s) to hold internal value(s)
    22.  
    23. ' Private constants, types and declares to call
    24. '
    25.  
    26. Const STYPE_DISKTREE            As Long = 0
    27. Const STYPE_PRINTQ              As Long = 1
    28. Const STYPE_DEVICE              As Long = 2
    29. Const STYPE_IPC                 As Long = 3
    30. Const STYPE_SPECIAL             As Long = &H80000000
    31.  
    32. Const ERROR_SUCCESS             As Long = 0&
    33. Const NERR_Success              As Long = 0&
    34. Const ERROR_ACCESS_DENIED       As Long = 5&
    35. Const ERROR_INVALID_LEVEL       As Long = 124&
    36. Const ERROR_INVALID_PARAMETER   As Long = 87&
    37. Const ERROR_MORE_DATA           As Long = 234&
    38. Const ERROR_NOT_ENOUGH_MEMORY   As Long = 8&
    39. Const ERROR_INVALID_NAME        As Long = 123&
    40.  
    41. Const NERR_BASE                 As Long = 2100&
    42. Const NERR_NetNameNotFound      As Long = (NERR_BASE + 210)
    43.  
    44.  
    45. Private Type SHARE_INFO_502
    46.   shi502_netname      As Long   ' LPWSTR shi502_netname;
    47.   shi502_type         As Long   ' DWORD shi502_type;
    48.   shi502_remark       As Long   ' LPWSTR shi502_remark;
    49.   shi502_permissions  As Long   ' DWORD shi502_permissions;
    50.   shi502_max_uses     As Long   ' DWORD shi502_max_uses;
    51.   shi502_current_uses As Long   ' DWORD shi502_current_uses;
    52.   shi502_path         As Long   ' LPWSTR shi502_path;
    53.   shi502_passwd       As Long   ' LPWSTR shi502_passwd;
    54.   shi502_reserved     As Long   ' DWORD shi502_reserved;
    55.   shi502_security_descriptor As Long ' PSECURITY_DESCRIPTOR shi502_security_descriptor;
    56. End Type
    57.  
    58. 'NET_API_STATUS NET_API_FUNCTION
    59. 'NetShareGetInfo (
    60. ' IN LPTSTR servername,
    61. ' IN LPTSTR netname,
    62. ' IN DWORD level,
    63. ' OUT LPBYTE * bufptr
    64. ' );
    65. Private Declare Function NetShareGetInfo Lib "Netapi32.dll" _
    66.   ( _
    67.     strServerName As Any, _
    68.     strNetName As Any, _
    69.     ByVal nLevel As Long, _
    70.     pBuffer As Long _
    71.   ) As Long
    72.  
    73. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    74. ( _
    75.   Destination As Any, _
    76.   ByVal Source As Any, _
    77.   ByVal Length As Long _
    78. )
    79.  
    80. Private Declare Function NetApiBufferFree Lib "Netapi32.dll" _
    81. ( _
    82.   ByVal lpBuffer As Long _
    83. ) As Long
    84.  
    85. Private Declare Sub lstrcpyW Lib "kernel32" _
    86. ( _
    87.   dest As Any, _
    88.   ByVal src As Any _
    89. )
    90.  
    91. Private Declare Function lstrlenW Lib "kernel32" _
    92. ( _
    93.   ByVal lpszString As Any _
    94. ) As Long
    95.  
    96. Continued....
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Convert UNC Path to local Drive and path

    VB Code:
    1. Public Property Get NET_API_STATUS() As Long
    2. 'used when retrieving value of a property, on the right side of an assignment.
    3. 'Syntax: Debug.Print X.NET_API_STATUS
    4.     NET_API_STATUS = mvarNET_API_STATUS
    5. End Property
    6.  
    7. Public Property Get strLastError() As Variant
    8. 'used when retrieving value of a property, on the right side of an assignment.
    9. 'Syntax: Debug.Print X.strLastError
    10.     If IsObject(mvarstrLastError) Then
    11.         Set strLastError = mvarstrLastError
    12.     Else
    13.         strLastError = mvarstrLastError
    14.     End If
    15. End Property
    16.  
    17. Public Property Get nLastError() As Long
    18. 'used when retrieving value of a property, on the right side of an assignment.
    19. 'Syntax: Debug.Print X.nLastError
    20.     nLastError = mvarnLastError
    21. End Property
    22.  
    23. Public Property Get strPath() As Variant
    24. 'used when retrieving value of a property, on the right side of an assignment.
    25. 'Syntax: Debug.Print X.strPath
    26.     If IsObject(mvarstrPath) Then
    27.         Set strPath = mvarstrPath
    28.     Else
    29.         strPath = mvarstrPath
    30.     End If
    31. End Property
    32.  
    33. Public Property Get nMax_uses() As Long
    34. 'used when retrieving value of a property, on the right side of an assignment.
    35. 'Syntax: Debug.Print X.nMax_uses
    36.   nMax_uses = mvarnMax_uses
    37. End Property
    38.  
    39. Public Property Get nCurrent_uses() As Long
    40. 'used when retrieving value of a property, on the right side of an assignment.
    41. 'Syntax: Debug.Print X.nCurrent_uses
    42.   nCurrent_uses = mvarnCurrent_uses
    43. End Property
    44.  
    45. Public Property Get strRemark() As Variant
    46. 'used when retrieving value of a property, on the right side of an assignment.
    47. 'Syntax: Debug.Print X.strRemark
    48.     If IsObject(mvarstrRemark) Then
    49.         Set strRemark = mvarstrRemark
    50.     Else
    51.         strRemark = mvarstrRemark
    52.     End If
    53. End Property
    54.  
    55. Public Property Get nType() As Long
    56. 'used when retrieving value of a property, on the right side of an assignment.
    57. 'Syntax: Debug.Print X.nType
    58.   nType = mvarnType
    59. End Property
    60.  
    61. Public Property Get strType() As Variant
    62. 'used when retrieving value of a property, on the right side of an assignment.
    63. 'Syntax: Debug.Print X.strType
    64.   Select Case mvarnType
    65.     Case STYPE_DISKTREE
    66.       strType = "Disk Drive"
    67.     Case STYPE_PRINTQ
    68.       strType = "Print Queue"
    69.     Case STYPE_DEVICE
    70.       strType = "Communication device"
    71.     Case STYPE_IPC
    72.       strType = "Interprocess communication (IPC)"
    73.     Case STYPE_SPECIAL
    74.       strType = "Special share"
    75.     Case Else
    76.       strType = "Error: Unknown"
    77.   End Select
    78. End Property
    79.  
    80. Public Property Get strNetName() As Variant
    81. 'used when retrieving value of a property, on the right side of an assignment.
    82. 'Syntax: Debug.Print X.strNetName
    83.     If IsObject(mvarstrNetName) Then
    84.         Set strNetName = mvarstrNetName
    85.     Else
    86.         strNetName = mvarstrNetName
    87.     End If
    88. End Property
    89.  
    90. Public Property Get strServer() As Variant
    91. 'used when retrieving value of a property, on the right side of an assignment.
    92. 'Syntax: Debug.Print X.strServer
    93.     If IsObject(mvarstrServer) Then
    94.         Set strServer = mvarstrServer
    95.     Else
    96.         strServer = mvarstrServer
    97.     End If
    98. End Property
    99. Public Sub Initialize()
    100.  
    101.   ' Reset the everything
    102.   '
    103.   mvarnLastError = 0
    104.   mvarstrLastError = ""
    105.   mvarstrServer = ""
    106.   mvarstrNetName = ""
    107.   mvarnType = 0
    108.   mvarstrRemark = ""
    109.   mvarnCurrent_uses = 0
    110.   mvarnMax_uses = 0
    111.   mvarstrPath = ""
    112.  
    113. End Sub
    114. Public Sub GetInfo(strShareName As Variant)
    115.   Dim pNetName()  As Byte
    116.   Dim pServer()   As Byte
    117.   Dim ptmpBuffer  As Long
    118.   Dim tmpBuffer   As SHARE_INFO_502
    119.   Dim strNetName  As String
    120.   Dim x As Integer
    121.  
    122.   Call Initialize
    123.  
    124.   ' copy the network share name without leading spaces.
    125.   '
    126.   strNetName = LTrim(strShareName)
    127.  
    128.   ' check for leading server in the name.
    129.   '
    130.   If Left(strNetName, 2) = "\\" Then
    131.  
    132.     ' find the end of the server in the name
    133.     '
    134.     x = InStr(3, strNetName, "\")
    135.  
    136.     ' only a server in the name
    137.     '
    138.     If x = 0 Then
    139.       mvarnLastError = ERROR_INVALID_NAME
    140.       mvarstrLastError = "Need share name not server name."
    141.       Exit Sub
    142.     Else
    143.       mvarstrServer = Left(strNetName, x - 1)
    144.       strNetName = Mid(strNetName, x + 1)
    145.     End If
    146.   End If
    147.  
    148.   ' strip off any remaining leading \
    149.   '
    150.   If Left(strNetName, 1) = "\" Then
    151.     strNetName = Mid(strNetName, 2)
    152.   End If
    153.  
    154.   ' Find the end of the share name.
    155.   '
    156.   x = InStr(strNetName, "\")
    157.   If x > 0 Then
    158.     strNetName = Left(strNetName, x - 1)
    159.   End If
    160.  
    161.   ' Check for drive letter
    162.   '
    163.   x = InStr(strNetName, ":")
    164.   If x > 0 Then
    165.     mvarnLastError = ERROR_INVALID_NAME
    166.     mvarstrLastError = "Drive letter specified for share name."
    167.     Exit Sub
    168.   End If
    169.  
    170.   ' Convert the string to a UNI string, happens automatically.
    171.   '
    172.   pNetName = strNetName & vbNullChar
    173.  
    174.   If Len(mvarstrServer) > 0 Then
    175.  
    176.     ' format the server name
    177.     '
    178.     If Left(mvarstrServer, 2) = "\\" Then
    179.       pServer = mvarstrServer & vbNullChar
    180.     Else
    181.       pServer = "\\" & mvarstrServer & vbNullChar
    182.     End If
    183.     ' Get the network infomation on the share.
    184.     '
    185.     mvarNET_API_STATUS = NetShareGetInfo _
    186.     ( _
    187.       pServer(0), _
    188.       pNetName(0), _
    189.       502, _
    190.       ptmpBuffer _
    191.     )
    192.   Else
    193.     ' Get the network infomation on the share.
    194.     ' NOTE: the first parameter is the server name, by sending a
    195.     ' null you are only looking at the current machine.
    196.     '
    197.     mvarNET_API_STATUS = NetShareGetInfo _
    198.     ( _
    199.       vbEmpty, _
    200.       pNetName(0), _
    201.       502, _
    202.       ptmpBuffer _
    203.     )
    204.   End If
    205.  
    206.   ' Check for errors.
    207.   If mvarNET_API_STATUS <> NERR_Success Then
    208.     Select Case mvarNET_API_STATUS
    209.       Case ERROR_ACCESS_DENIED
    210.         mvarstrLastError = "NetShareGetInfo: ERROR_ACCESS_DENIED"
    211.       Case ERROR_INVALID_LEVEL
    212.         mvarstrLastError = "NetShareGetInfo: ERROR_INVALID_LEVEL"
    213.       Case ERROR_INVALID_PARAMETER
    214.         mvarstrLastError = "NetShareGetInfo: ERROR_INVALID_PARAMETER"
    215.       Case ERROR_MORE_DATA
    216.         mvarstrLastError = "NetShareGetInfo: ERROR_MORE_DATA"
    217.       Case ERROR_NOT_ENOUGH_MEMORY
    218.         mvarstrLastError = "NetShareGetInfo: ERROR_NOT_ENOUGH_MEMORY"
    219.       Case ERROR_INVALID_NAME
    220.         mvarstrLastError = "NetShareGetInfo: ERROR_INVALID_NAME"
    221.       Case NERR_NetNameNotFound
    222.         mvarstrLastError = "NetShareGetInfo: NERR_NetNameNotFound"
    223.       Case Else
    224.         mvarstrLastError = "NetShareGetInfo: Unknown " & mvarNET_API_STATUS
    225.     End Select
    226.     mvarnLastError = mvarNET_API_STATUS
    227.     Exit Sub
    228.   End If
    229.  
    230.   ' Copy the return buffer to a type definition for processing.
    231.   Call CopyMemory(tmpBuffer, ptmpBuffer, LenB(tmpBuffer))
    232.  
    233.   ' save the return buffer information.
    234.   mvarstrNetName = UtoA(tmpBuffer.shi502_netname)
    235.   mvarnType = tmpBuffer.shi502_type
    236.   mvarstrRemark = UtoA(tmpBuffer.shi502_remark)
    237.   mvarnCurrent_uses = tmpBuffer.shi502_current_uses
    238.   mvarnMax_uses = tmpBuffer.shi502_max_uses
    239.   mvarstrPath = UtoA(tmpBuffer.shi502_path)
    240.  
    241.   ' Free the buffer.
    242.   mvarNET_API_STATUS = NetApiBufferFree(ptmpBuffer)
    243.  
    244.   ' Check for errors.
    245.   If mvarNET_API_STATUS <> ERROR_SUCCESS Then
    246.     mvarnLastError = mvarNET_API_STATUS
    247.     mvarstrLastError = "NetApiBufferFree: Unknown"
    248.     Exit Sub
    249.   End If
    250. End Sub
    251. Private Function UtoA(pUNIstring As Long) As String
    252.   Dim wrkByte()   As Byte
    253.   Dim wrkStr      As String
    254.  
    255.   ' Get space for string each character is two bytes and a null terminator.
    256.   ReDim wrkByte(lstrlenW(pUNIstring) * 2 + 2)
    257.  
    258.   ' Copy the string to a byte array
    259.   Call lstrcpyW(wrkByte(0), pUNIstring)
    260.  
    261.   ' Covert the string from a UNI string to a ASCII string.
    262.   ' this happens automatically when a byte array is copied to a string.
    263.   wrkStr = wrkByte
    264.  
    265.   ' return everything upto the the null terminator.
    266.   UtoA = Left(wrkStr, InStr(wrkStr, Chr(0)) - 1)
    267. End Function
    268.  
    269. 'In a form
    270. Option Explicit
    271. Private Sub Form_Load()
    272.   m_lblStatus.Caption = ""
    273.  
    274.   ' Good test - admin share
    275.   TestShareGetInfo "admin$"
    276.  
    277.   ' Good test - share with leading slash
    278.   TestShareGetInfo "\admin$"
    279.  
    280.   ' Good test - share with trailing slash
    281.   TestShareGetInfo "admin$\"
    282.  
    283.   ' Good test - share with trailing slash
    284.   TestShareGetInfo "\admin$\"
    285.  
    286.   ' Good test
    287.   TestShareGetInfo "testdata"
    288.  
    289.   ' Good test - should not have server name, but we fix that
    290.   TestShareGetInfo "\\lee\testdata"
    291.  
    292.   ' Good test - should not have server name, but we fix that
    293.   TestShareGetInfo "\\lee\admin$"
    294.  
    295.   ' *** Good test - remote server
    296.   TestShareGetInfo "\\maggie\admin$"
    297.  
    298.   ' *** Bad test - no share
    299.   TestShareGetInfo "NoShareCalledThis"
    300.  
    301.   ' *** Bad test - no remote share
    302.   TestShareGetInfo "\\maggie\NoShareCalledThis"
    303.  
    304. End Sub
    305. Private Sub TestShareGetInfo(strShare As String)
    306.   Dim x As New CprgNetShareGetInfo
    307.  
    308.   m_lblStatus.Caption = m_lblStatus.Caption & "Test Share: " & strShare & " = "
    309.  
    310.   x.GetInfo strShare
    311.   If x.nLastError = 0 Then
    312.     m_lblStatus.Caption = m_lblStatus.Caption _
    313.       & vbCrLf & " Server: " & x.strServer & " Path: " & x.strPath & vbCrLf
    314.   Else
    315.     m_lblStatus.Caption = m_lblStatus.Caption & vbCrLf & " Error: " _
    316.       & x.nLastError & " " & x.strLastError & vbCrLf
    317.   End If
    318. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Convert UNC Path to local Drive and path

    RobDog888,

    That's a lot of code... I wrote the routine to do what I needed, but I thought it was just one API long ago...
    VB Code:
    1. sPath = TranslatePath("\\192.168.1.100\Shared Folder\Folder\")
    2.  
    3. Private Sub TranslatePath() as String
    4. Dim NetInfo As Variant
    5.  
    6.    NetInfo = GetNetworkDrives
    7.    TranslatePath= GetLocalName(sPath, NetInfo)
    8.  
    9. End Sub
    10.  
    11. Public Function GetLocalName(sPath As String, sNet As Variant)
    12. Dim i As Long
    13. Dim sVar As Variant
    14.  
    15.     GetLocalName = sPath
    16.    
    17.     For i = LBound(sNet) To UBound(sNet)
    18.         sVar = Split(sNet(i), ",")
    19.         If Right(sVar(1), 1) <> "\" Then sVar(1) = sVar(1) & "\"
    20.        
    21.         If InStr(sPath, sVar(1)) > 0 Then
    22.             GetLocalName = sVar(0) & Mid(sPath, Len(sVar(1))) ' Create the Mapped drive and path name
    23.             Exit For
    24.         End If
    25.        
    26.     Next i
    27.    
    28. End Function
    29.  
    30. Public Function GetNetworkDrives() As Variant
    31. Dim hEnum As Long
    32. Dim NetInfo(1023) As NETRESOURCE
    33. Dim entries As Long
    34. Dim nStatus As Long
    35. Dim LocalName As String
    36. Dim UNCName As String
    37. Dim i As Long
    38. Dim j As Long
    39. Dim r As Long
    40. Dim AR() As String
    41.  
    42.     ' Modified from Original Code By Randem Systems, INC
    43.     '
    44.     'KPD-Team 1999
    45.     'URL: [url]http://www.allapi.net/[/url]
    46.     'E-Mail: [email][email protected][/email]
    47.     '-> This sample was created by Donald Grover
    48.  
    49.     ' Begin the enumeration
    50.     nStatus = WNetOpenEnum(RESOURCE_CONNECTED, RESOURCETYPE_ANY, 0&, ByVal 0&, hEnum)
    51.  
    52. '    LetterToUNC = DriveLetter
    53.  
    54.     'Check for success from open enum
    55.     If ((nStatus = 0) And (hEnum <> 0)) Then
    56.         ' Set number of entries
    57.         entries = 1024
    58.  
    59.         ' Enumerate the resource
    60.         nStatus = WNetEnumResource(hEnum, entries, NetInfo(0), CLng(Len(NetInfo(0))) * 1024)
    61.  
    62.         ' Check for success
    63.         If nStatus = 0 Then
    64.        
    65.             For i = 0 To entries - 1
    66.                 ' Get the local name
    67.                 LocalName = ""
    68.                 If NetInfo(i).lpLocalName <> 0 Then
    69.                     LocalName = Space(lstrlen(NetInfo(i).lpLocalName) + 1)
    70.                     r = lstrcpy(LocalName, NetInfo(i).lpLocalName)
    71.                 End If
    72.  
    73.                 ' Strip null character from end
    74.                 If Len(LocalName) <> 0 Then
    75.                     LocalName = Left(LocalName, (Len(LocalName) - 1))
    76.                 End If
    77.  
    78.                     ' Get the remote name
    79.                     UNCName = ""
    80.                     If NetInfo(i).lpRemoteName <> 0 Then
    81.                         UNCName = Space(lstrlen(NetInfo(i).lpRemoteName) + 1)
    82.                         r = lstrcpy(UNCName, NetInfo(i).lpRemoteName)
    83.                     End If
    84.  
    85.                     ' Strip null character from end
    86.                     If Len(UNCName) <> 0 Then
    87.                         UNCName = Left(UNCName, (Len(UNCName) - 1))
    88.                     End If
    89.  
    90.                     On Error Resume Next
    91.                     j = UBound(AR) + 1
    92.                     ReDim Preserve AR(j)
    93.                     AR(j) = LocalName & "," & UNCName
    94.                     On Error GoTo 0
    95.                    
    96.                     Exit For
    97.             Next i
    98.            
    99.         End If
    100.        
    101.     End If
    102.  
    103.     ' End enumeration
    104.     nStatus = WNetCloseEnum(hEnum)
    105.     mGetNetworkDrives = AR()
    106.    
    107. End Function

  10. #10
    Hyperactive Member umilmi81's Avatar
    Join Date
    Sep 2005
    Location
    Sterling Heights, Mi.
    Posts
    335

    Re: Convert UNC Path to local Drive and path

    Quote Originally Posted by randem
    That does exactly the OPPOSITE of what I asked for...???

    Well you could work in reverse right? Loop through your mapped drives and stop when it matches the server you're looking for.

  11. #11

    Thread Starter
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: Convert UNC Path to local Drive and path

    umilmi81,

    Yes, I have done that. I was looking for an API that I thought existed at one time.

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Convert UNC Path to local Drive and path

    The class isnt too bad but to use the class is not more then x.GetInfo strShare to place the call and x.strServer and x.strPath. Its worked perfectly for me in my app for about 2 years now.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width