PDA

Vollständige Version anzeigen : Server-Adresse ermitteln


Mike
16.01.2001, 13:35
Hallo,
wie ermittle ich die komplette Serveradresse anstelle des Laufwerkbuchstabens?
Mike

Manuela Kulpa
16.01.2001, 14:54
Guten Tag Mike!

So geht's ....

Public Declare Function WNetGetConnection Lib "mpr.dll" Alias
"WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As
String, cbRemoteName As Long) As Long


Public Function GetUNCPath(ByVal sLocalPath As String) As String
'// -----------------------------------------------------------------
'// Methode: | Konvertiert einen Pfad in UNC-Pfad (\\ SERVER\...)
'// -----------------------------------------------------------------
'// Parameter: | sLocalPath = gültiger, lokaler Pfad (X:\..)
'// -----------------------------------------------------------------
'// Rückgabe: | bei Erfolg = UNC-Pfad
'// | bei Fehler = sLocalPath
'// -----------------------------------------------------------------
Const MAXPATH As Long = 260
Const NO_ERROR As Long = 0

Dim sUNCPath As String
Dim sResult As String
Dim sDrive As String

On Error Resume Next
GetUNCPath = sLocalPath
If VBA.Mid$(sLocalPath, 2, 1) <> ":" Then Exit Function
'// Die API-Funktion benötigt nur das Laufwerk!
sDrive = VBA.Left$(sLocalPath, 2)
sUNCPath = VBA.String(MAXPATH, 0)
If WNetGetConnection(sDrive, sUNCPath, VBA.Len(sUNCPath)) = NO_ERROR
Then
sResult = VBA.Left$(sUNCPath, VBA.InStr(sUNCPath, vbNullChar) - 1)
If VBA.Len(sResult) > 0 Then
GetUNCPath = sResult & VBA.Mid$(sLocalPath, 3)
End If
End If

End Function

LLAP

Mike
16.01.2001, 17:54
Hallo Manuela,

prompte und treffende Antwort!
Ich danke dir.
Mike