Results 1 to 3 of 3

Thread: Get a UNC path from a local Share?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 1999
    Location
    Sunny Southern Weather
    Posts
    406

    Get a UNC path from a local Share?

    I'm trying to determine the UNC PATH of a shared folder
    which could be on a user's local machine OR is could be a mapped drive.

    For example, on my pc named "MYPC", if I share a folder called "Junk", the correct UNC path would be "\\MYPC\Junk".

    Also, if I map a different machine's drive/folder, I would expect the same kind of returned path.
    For example, I map drive F: to a different machine named "THEIR_PC" and select a folder "their_folder".
    The UNC Path would be "\\THEIR_PC\their_folder".

    I'd like to be able to take a path from a CommonDialogBox and 'convert' it to the UNC path.

    For example, the user opens the commondialog, and selects the local shared folder "C:\test_folder" on their machine "THEIR_PC"
    I then convert "C:\test_folder" to: "\\THEIR_PC\test_folder"

    Example 2:
    The user opens the commondialog, and selects the mapped folder
    "F:\sample" on a different machine named "ANOTHERPC"
    I convert "F:\sample" to: "\\ANOTHERPC\sample".

    (Did I beat the horse enough?)

  2. #2
    Fanatic Member robbedaya's Avatar
    Join Date
    Jul 2002
    Location
    Belgium
    Posts
    872
    maybe you could use this: This is code that gets the computername of a computer
    VB Code:
    1. Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    2. Private Sub Form_Load()
    3.     Dim strString As String
    4.     'Create a buffer
    5.     strString = String(255, Chr$(0))
    6.     'Get the computer name
    7.     GetComputerName strString, 255
    8.     'remove the unnecessary chr$(0)'s
    9.     strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
    10.     'Show the computer name
    11.     MsgBox strString
    12. End Sub
    - Use the thread tools to Mark your Thread as Resolved when your question is answered.
    - Please Rate my answers if they where helpful.

  3. #3
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357
    You said the first half of your problem was solved on your last thread, so here's how to solve the second half (getting the share name of mapped drives).

    This requires a reference to Microsoft Scripting Runtime:
    VB Code:
    1. Dim oFSO As FileSystemObject
    2.     Dim oDrive As Drive
    3.    
    4.     Set oFSO = New FileSystemObject
    5.    
    6.     For Each oDrive In oFSO.Drives
    7.         If oDrive.DriveType = Remote Then
    8.             MsgBox oDrive.DriveLetter & " = " & oDrive.ShareName
    9.         End If
    10.     Next
    11.    
    12.     Set oFSO = Nothing
    So, when a folder is selected from the CommonDialog, you can first get the drive letter and modify the above code to see if it's a mapped drive. If not, then use the code in your other post to see if it's a shared folder.
    Last edited by seaweed; Apr 18th, 2003 at 12:29 PM.
    ~seaweed

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