|
|
|
|
|
Dicas
|
|
Visual Basic (Redes/Comunicações)
|
|
|
Título da Dica: Obter o caminho UNC de um drive de rede ou descobrir que ele é local
|
|
|
|
Postada em 11/2/2004 por PC
Option Explicit
'Esta API retorna o caminho UNC, se ele for retornado em branco o drive não é mapeado, mas sim local.
Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, cbRemoteName As Long) As Long
Function GetUNCPath(ByVal strDriveLetter As String, ByRef strUNCPath As String) As Long
On Local Error GoTo GetUNCPath_Err
Dim strMsg As String Dim lngReturn As Long Dim strLocalName As String Dim strRemoteName As String Dim lngRemoteName As Long
DoEvents strLocalName = strDriveLetter strRemoteName = String$(255, Chr$(32)) lngRemoteName = Len(strRemoteName)
'Attempt to grab UNC lngReturn = WNetGetConnection(strLocalName, _ strRemoteName, _ lngRemoteName)
If lngReturn = NO_ERROR Then 'No problems - return the UNC 'to the passed ByRef string GetUNCPath = NO_ERROR strUNCPath = Trim$(strRemoteName) strUNCPath = Left$(strUNCPath, Len(strUNCPath) - 1) Else 'Problems - so return original 'drive letter and error number GetUNCPath = lngReturn strUNCPath = strDriveLetter & "\" End If GetUNCPath_End: Exit Function GetUNCPath_Err: GetUNCPath = ERROR_NOT_SUPPORTED strUNCPath = strDriveLetter Resume GetUNCPath_End End Function
|
|
|
|
|