Folks,
I found what I need to use. Thanks to NathanN!
Option Explicit '// 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 = 255
Function UNCPath(sDriveLetter 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. sDriveLetter = sDriveLetter & ":"
'// 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( _ sDriveLetter, _ lpszRemoteName, _ cbRemoteName)
'// Has WNetGetConnection() succeeded. '// WNetGetConnection()returns 0 (NO_ERROR) '// if it succesfully retrieves the UNC path. If lStatus = NO_ERROR Then ' Display the UNC path. UNCPath = lpszRemoteName Else ' Unable to obtain the UNC path. UNCPath = "NO UNC path" End If
End Function
Sub GetUNCPath() Dim sDriveLetter As String Dim cbRemoteName As Long Dim lStatus As Long
Again: '// Prompt the user to type the mapped drive letter. sDriveLetter = UCase(InputBox( _ "Enter Drive Letter of Your Network" & _ "Connection." & Chr(10) & "eg. Y (NO colon)")) If sDriveLetter = "" Then End If Len(sDriveLetter) > 1 Then GoTo Again
'// Add a colon to the drive letter entered. sDriveLetter = sDriveLetter & ":"
'// 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(sDriveLetter, _ lpszRemoteName, _ cbRemoteName)
'// Has WNetGetConnection() succeeded. '// WNetGetConnection()returns 0 (NO_ERROR) '// if it succesfully retrieves the UNC path. If lStatus& = NO_ERROR Then '// Display the UNC path. MsgBox lpszRemoteName, vbInformation Else '// Unable to obtain the UNC path. MsgBox "Unable to obtain the UNC path for " & _ sDriveLetter, vbInformation End If
End Sub
Guy Edk> > For all you clever systems people out there:
> >
> > When getting the path of an item in SW (GetPathName)it returns the
> > mapped drive for the current session. Is there any way to get the UNC
> > path instead? Using subclassing the Windows API perhaps? This avoids
> > problems on systems without the same mappings for an application
> > currently under development.
>
> SW doesn't seem to understand the notion of UNC paths. This is whay you
> can't have two different parts with the same name open at the same time.
> Despite being two unique, easily distinguishable files, SW dumbly
> looks at the file name only.
>
> On top of that, as you have discovered, you have the problem with mapped
> drives. Everyone working on a common project must have the same drive
> mappings or they must browse using the full UNC paths from Network
> Neighborhood. Aggravating.
>
> Jim S.
>