'// 32-bit Function version.
'// Note:
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 = 1052
Function fnUNCPath(strDriveLetter As String) As String
'// Takes specified Local Drive Letter
'// eg E,D,H Etc and converts to UNC
Dim cbRemoteName As Long
Dim lStatus As Long
'// Add a colon to the drive letter entered.
strDriveLetter = Left(strDriveLetter, 1) & ":"
'// Specifies the size in charaters of the buffer.
cbRemoteName = lBUFFER_SIZE
'// Prepare a string variable by padding spaces.
lpszRemoteName = lpszRemoteName & Space(lBUFFER_SIZE)
'// Return the UNC path (eg.\\Server\Share).
lStatus = WNetGetConnection32( _
strDriveLetter, _
lpszRemoteName, _
cbRemoteName)
'// Has WNetGetConnection() succeeded.
'// WNetGetConnection()returns 0 (NO_ERROR)
'// if it succesfully retrieves the UNC path.
If lStatus = NO_ERROR Then
'// Get UNC path.
fnUNCPath = lpszRemoteName
Else
'// Unable to obtain the UNC path.
fnUNCPath = "NO UNC path"
End If
End Function