is there any posibility to get the UNC-path from a mapped directory?
Thanks for your help.
Daniel Walzenbach
"Daniel Walzenbach" <dani...@web.de> wrote in message
news:u7G9U0KzCHA.1768@TK2MSFTNGP12...
is there no way the .NET framework supports this feature?
I mean... it's nice to see the network mappings but how can I use them
in my program? could cou kindly post some lines of code?
Thanks a lot.
Similarly you can use the same class to map Network directories.
Here is a Simple Class named "MapDirCode" which does both the tasks for you.
Public Class MapDirCode
Public Shared Sub main()
ViewMappedDrives()
MapNetworkDrives()
ViewMappedDrives()
End Sub
Shared Sub MapNetworkDrives()
Dim WshNetwork As Object
WshNetwork = CreateObject("WScript.Network")
WshNetwork.MapNetworkDrive("G:", "\\Comp001\MyDir")
WshNetwork = Nothing
End Sub
Shared Sub ViewMappedDrives()
Dim WshNetwork As Object
Dim oDrives As Object
Dim i As Integer
WshNetwork = CreateObject("WScript.Network")
Console.WriteLine("Network Drive Mappings")
oDrives = WshNetwork.EnumNetworkDrives
For i = 0 To oDrives.Count - 1 Step 2
Console.WriteLine("Drive " & oDrives.Item(i) & " = " &
oDrives.Item(i + 1))
Next
oDrives = Nothing
WshNetwork = Nothing
End Sub
End Class
Regards
Vaibhav Modak
Maximizelearning
www.maximizelearning.com
"Daniel Walzenbach" <dani...@web.de> wrote in message
news:u7G9U0KzCHA.1768@TK2MSFTNGP12...
HTH - Lee Gillie
"Daniel Walzenbach" <dani...@web.de> wrote in message
news:u7G9U0KzCHA.1768@TK2MSFTNGP12...
Can you elaborate the use of the same by giving a short Code Sample,
Thanks & Regards,
Vaibhav Modak
Maximizelearning
www.maximizelearning.com
"Lee Gillie" <DESP...@odp.comMAPSED> wrote in message
news:#u#e9ntzCHA.428@TK2MSFTNGP09...
WNetGetUniversalName is Unicode function of the netapi32.dll ?! Declare one
of
the structs and place a declaration for this function in your code. With
lstrlenW and
lstrcpyW you get then the strings from the pointers.
Regards
Holger
"Vaibhav Modak" <vaib...@hotmail.com> schrieb im Newsbeitrag
news:OxUE8uL0CHA.1628@TK2MSFTNGP10...
Sure...
You first need some declarations, which I do like this:
Private Declare Auto Function WNetGetUniversalName Lib "mpr.dll" ( _
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> _
ByVal lpLocalPath As String, _
ByVal dwInfoLevel As INFO_LEVEL, _
ByVal lpBuffer As IntPtr, _
ByRef lpBufferSize As Integer _
) As Integer
Private Structure REMOTE_NAME_INFO
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> _
Public lpUniversalName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> _
Public lpConnectionName As String
<MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPTStr)> _
Public lpRemainingPath As String
End Structure
Private Enum INFO_LEVEL As Integer
UNIVERSAL_NAME_INFO_LEVEL = 1
REMOTE_NAME_INFO_LEVEL = 2
End Enum
And then, for my purposes, I create a VB wrapper function:
Public Function GetUniversalName( _
ByVal Path As String, _
ByRef UniversalName As String, _
ByRef ConnectionName As String, _
ByRef RemainingPath As String) As Boolean
' When successful, returns TRUE with UniversalName,
' ConnectionName, and RemainingPath data. If not
' successful, it may be the drive is local and not mapped.
Dim buffer As Integer
Dim ptrbuffer As IntPtr
Dim status As Integer
Dim rni As REMOTE_NAME_INFO
Dim Success As Boolean
Dim SafteyCount As Integer = 0
UniversalName = ""
ConnectionName = ""
RemainingPath = ""
buffer = 1024
ptrbuffer = Marshal.AllocHGlobal(buffer)
status = WNetGetUniversalName( _
Path, INFO_LEVEL.REMOTE_NAME_INFO_LEVEL, _
ptrbuffer, buffer)
Do While True
Select Case status
Case NO_ERROR
rni = Marshal.PtrToStructure(ptrbuffer, GetType(REMOTE_NAME_INFO))
UniversalName = rni.lpUniversalName
ConnectionName = rni.lpConnectionName
RemainingPath = rni.lpRemainingPath
Success = True
Exit Do
Case ERROR_MORE_DATA
If SafteyCount > 3 Then
Success = False
Exit Do
End If
SafteyCount += 1
Marshal.FreeHGlobal(ptrbuffer)
ptrbuffer = Marshal.AllocHGlobal(buffer)
status = WNetGetUniversalName(Path, _
INFO_LEVEL.REMOTE_NAME_INFO_LEVEL, ptrbuffer, buffer)
Case Else
Success = False
Exit Do
End Select
Loop
Marshal.FreeHGlobal(ptrbuffer)
Return Success
End Function
You could probably do this better, but the above seems to work for me.
Hope this helps.
- Lee Gillie
"Vaibhav Modak" <vaib...@hotmail.com> wrote in message
news:OxUE8uL0CHA.1628@TK2MSFTNGP10...
Regards,
Vaibhav Modak
"Lee Gillie" <DESP...@odp.comMAPSED> wrote in message
news:Or84QmS0CHA.1728@TK2MSFTNGP12...