Bodo
> wie kann ich für einen gemappten Netzwerkpfad den zugehörigen UNC-Pfad
> ermitteln? Beispiel: H:\temp.txt
> gewünschtes Ergebnis: \\Server1\Freigabe1\Ordner1\temp.txt
vermutlich nur per PInvoke,
Win32 WNetGetUniversalName
http://msdn.microsoft.com/library/en-us/wnet/wnet/wnetgetuniversalname.asp
Bsp etwa wie:
http://groups.google.de/group/microsoft.public.dotnet.framework.interop/msg/6ae7a0083cf7915c
--
Thomas Scheidegger - MVP .NET - 'NETMaster'
http://www.cetus-links.org/oo_dotnet.html - http://dnetmaster.net/
"Bodo Jäger" <bodo....@weinig.de> schrieb im Newsbeitrag
news:eQjSfeU...@TK2MSFTNGP11.phx.gbl...
ich mach's so:
Public Function Local2UNC(ByVal PathName As String) As String
'Option Compare Text einstellen
'
Dim PathArray() As String = PathName.Split(":\")
Dim allDrives() As DriveInfo = DriveInfo.GetDrives()
Local2UNC = PathName
Dim d As DriveInfo
For Each d In allDrives
If d.Name = PathArray(0) & ":\" AndAlso d.DriveType =
DriveType.Network Then
Dim RegKey As String
RegKey = "HKEY_CURRENT_USER\Volatile Environment"
If My.Computer.Registry.GetValue(RegKey, "HOMEDRIVE",
Nothing) = PathArray(0) & ":" Then
Return My.Computer.Registry.GetValue(RegKey,
"HOMESHARE", Nothing) & "\" & PathArray(1)
Else
RegKey = "HKEY_CURRENT_USER\NetWork\" & PathArray(0)
Return My.Computer.Registry.GetValue(RegKey,
"RemotePath", Nothing) & "\" & PathArray(1)
End If
End If
Next
End Function
Gruß
Andreas
Ich hab jetzt, aufgrund des Links von Thomas, folgende Funktion:
Imports System.Text
Imports System.Runtime.InteropServices
Module UNC
<DllImport("mpr.dll", SetLastError:=False, CharSet:=CharSet.Auto)> _
Function WNetGetConnection( _
ByVal localName As String, _
ByVal remoteName As StringBuilder, _
ByRef remoteSize As Int32) As Int32
End Function
Public Function UNC_Pfad(ByVal Pfad)
Try
Dim sb As New StringBuilder(300)
Dim sb2 As New StringBuilder
sb2.Append(Pfad)
Dim size As Int32 = sb.Capacity
Dim Laufwerk As String = Split(Pfad, "\")(0)
WNetGetConnection(Laufwerk, sb, size)
Dim UNC As String = sb.ToString
sb2.Replace(Laufwerk, UNC)
Return sb2.ToString
Catch ex As Exception
Throw ex
End Try
End Function
End Module
Bodo
nur eine Vermutung,
Windows Logon-Scripts (Batch) können oft auch Mappings erstellen.
(Kommandozeile: net use ... )
oder evtl. ab Server via ActiveDirectory Policy o.ä.