|
-
Apr 18th, 2003, 11:23 AM
#1
Thread Starter
Hyperactive Member
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?)
-
Apr 18th, 2003, 12:14 PM
#2
Fanatic Member
maybe you could use this: This is code that gets the computername of a computer
VB Code:
Private Declare Function GetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Private Sub Form_Load()
Dim strString As String
'Create a buffer
strString = String(255, Chr$(0))
'Get the computer name
GetComputerName strString, 255
'remove the unnecessary chr$(0)'s
strString = Left$(strString, InStr(1, strString, Chr$(0)) - 1)
'Show the computer name
MsgBox strString
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.
-
Apr 18th, 2003, 12:25 PM
#3
Frenzied Member
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:
Dim oFSO As FileSystemObject
Dim oDrive As Drive
Set oFSO = New FileSystemObject
For Each oDrive In oFSO.Drives
If oDrive.DriveType = Remote Then
MsgBox oDrive.DriveLetter & " = " & oDrive.ShareName
End If
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|