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

How do I get UNC pathing string from Network Drive letter 1

Status
Not open for further replies.

WantsToLearn

Programmer
Feb 15, 2003
147
US
Is there a function or API call that returns the UNC pathing string (eg H: - \\server1\help\data)?

Thank you
 
This should work for you...


' 32-bit Function version.
Declare Function WNetGetConnection32 Lib "MPR.DLL" Alias _
"WNetGetConnectionA" (ByVal lpszLocalName As String, _
ByVal lpszRemoteName As String, lSize As Long) As Long

' 32-bit declarations:
Dim lpszRemoteName As String
Dim lSize As Long

' Use for the return value of WNetGetConnection() API.
Const NO_ERROR As Long = 0

' The size used for the string buffer. Adjust this if you
' need a larger buffer.
Const lBUFFER_SIZE As Long = 255
Sub getNetPath()

DriveLetter = UCase(InputBox("Enter Drive Letter of Your _
Network" & "Connection." & Chr(10) & "i.e. F (do not _
enter a colon)", "Find Network Path..."))
DriveLetter = DriveLetter & ":"

cbRemoteName = lBUFFER_SIZE ' Specifies the size in charaters of the buffer.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE) ' Prepare a string variable by padding spaces.
lStatus& = WNetGetConnection32(DriveLetter, _
lpszRemoteName, cbRemoteName)
' Return the UNC path (\\Server\Share).

If lStatus& = NO_ERROR Then ' Returns 0 (NO_ERROR) if succesful.
MsgBox lpszRemoteName, vbInformation, "Path Found"
Else
MsgBox "Unable to obtain the UNC path.", vbInformation, "Error"
End If

End Sub


 
Thanks! That worked great at soon as I dimensioned the following variables:

Dim DriveLetter As String
Dim cbRemoteName As Long
Dim lStatus As Long

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top