Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the Physical Path of a Mapped Network Drive

Status
Not open for further replies.

mikemcginty

Programmer
Joined
Jul 11, 2002
Messages
184
Location
AU
Is there any way in Visual Basic of retrieving the physical path of a mapped network drive?

I have tried FileSystemObject.GetAbsolutePathName but this only returns the mapped path

For example if physical drive J:\PFolder1\PFolder2 is mapped to Q:\. (Note: J:\ does not show in Windows Explorer but Q:\ does)

Now I now want to retrieve the physical path of
Q:\FolderA\FolderB
as
J:\PFolder1\PFolder2\FolderA\FolderB

Any help would be appreciated


When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
Thanks taupirho

I did find similar code elsewhere and tried it but it didn't work. It returns a blank string.



When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
I'm pretty sure it can be done in vbscript. How about you use vbscript to write the mapping string to a file. Call the vbscript within vb, then read the vbscript created file in vb.

Clunky, I know but I think it would work OK.
 
You can get this information using Windows Scripting Host.

Add a reference to Windows Script Host Object Model and try the following code.
___
[tt]
Function GetUNCPath(LocalDrive As String) As String
With New WshNetwork
With .EnumNetworkDrives
Dim NetDrives As Object, N As Long
For N = 0 To .Count - 1 Step 2
If LocalDrive = .Item(N) Then
GetUNCPath = .Item(N + 1)
Exit Function
End If
Next
End With
End With
End Function

Private Sub Form_Load()
MsgBox GetUNCPath("Z:")
End Sub[/tt]
 
Thanks Hypetia

The function only returns \\servername\PFolder1\PFolder2\ but does not show the physical drive (ie J:\PFolder1\PFolder2\)

Mike

When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top