1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
Public Declare Function WNetGetConnection Lib "mpr.dll" Alias "WNetGetConnectionA" (ByVal lpszLocalName As String, ByVal lpszRemoteName As String, ByRef cbRemoteName As Integer) As Integer
Public Shared Function CheckNetworkDrive(path As String) As String
'--- Détecte si le chemin donné est sur un lecteur réseau, si le cas, convertion en chemin unc complet -> \\serveur\partage\... ----
Dim ret As Integer
Dim out As String = New String(" "c, 260)
Dim len As Integer = 260
ret = WNetGetConnection(IO.Path.GetPathRoot(path).Substring(0, 2), out, len)
out = out.Replace(vbNullChar, "").Trim
If out.Trim <> String.Empty Then
If Not path.StartsWith(out) Then
path = IO.Path.Combine(out, path.Replace(IO.Path.GetPathRoot(path), ""))
Return path
End If
End If
Return path
End Function |
Partager