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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrive UNC Path

Status
Not open for further replies.

Kocheace

Vendor
Oct 31, 2002
97
0
0
US
I have a feature in an application that I created that is triggered when the user clicks in a text box. Once it has the focus a dialog box appears in which they go to the location of the file that they want. Once the file is selected a link is created for the file.

The problem is that different computers have different letters representing the network drive where the images are. So if everyones drive letters are different and they create a link to a file others can't access it.

Does anyone know of a way to retrieve the UNCPath of a networked drive? I've copied code from microsoft but it doesn't work. It uses the MPR.dll file but somethings up with it. Any suggestions would be greatly appreciated.

P.S. Sorry for the long thread

IT Professional
 
The following should work. You need to set a reference to 'Windows Script Host Object Model'

Function PathTransToUNC(sPath As String) As String
Dim oWSHNet As Object, drv
Dim sDriveLetter As String, sUNC As String
Dim bNextOne As Boolean

bNextOne = False
sDriveLetter = Left(sPath, 2)

If sDriveLetter = "\\" Then
' Already a UNC Path
PathTransToUNC = sPath
Else
' Translate
Set oWSHNet = CreateObject("WScript.Network")

For Each drv In oWSHNet.EnumNetworkDrives
If bNextOne Then
sUNC = drv
bNextOne = False
End If
If Left(drv, 2) = sDriveLetter Then
bNextOne = True
End If
Next drv

Set oWSHNet = Nothing

PathTransToUNC = sUNC & Mid(sPath, 3)
End If
End Function

To call.. ?PathTransToUNC("M:")

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top