Forum: VB.NET |
Thema:
AW: AW: AW: net use mit VB2005 |
Von:
M Merlin (
03.05.2007 13:58) |
Ich bin da jetzt schon ein ganzes Stück voran gekommen:
Es klappt wenn ich ein Laufwerk ohne User und Password mappe wenn ich dies mit den Paramentern möchte funktioniert es nicht...
Hat jamand eine Idee.....? Hier meine Code....
Public Declare Function WNetAddConnection2 Lib "mpr.dll" Alias "WNetAddConnection2A" (ByRef lpNetResource As NETRESOURCE, ByVal lpPassword As String, ByVal lpUserName As String, ByVal dwFlags As Integer) As Integer
Public Declare Function WNetCancelConnection2 Lib "mpr" Alias "WNetCancelConnection2A" (ByVal lpName As String, ByVal dwFlags As Integer, ByVal fForce As Integer) As Integer
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> Public Structure NETRESOURCE
Public dwScope As Integer
Public dwType As Integer
Public dwDisplayType As Integer
Public dwUsage As Integer
Public lpLocalName As String
Public lpRemoteName As String
Public lpComment As String
Public lpProvider As String
End Structure
Public Const ForceDisconnect As Integer = 1
Public Const RESOURCETYPE_DISK As Long = &H1
Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String, ByVal UserName As String, ByVal PassWord As String, ByRef errMsg As String) As Boolean
Dim nr As NETRESOURCE
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter & ":"
If UserName = String.Empty Then UserName = Nothing '(add parameters to pass this if necessary)
If PassWord = String.Empty Then PassWord = Nothing '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
Dim result As Integer
Try
result = WNetAddConnection2(nr, PassWord, UserName, 0)
Catch ex As Exception
errMsg = ex.Message
End Try
errMsg = result.ToString
If result = 0 Then
Return True
Else
Return False
End If
End Function
Public Function UnMapDrive(ByVal DriveLetter As String) As Boolean
Dim rc As Integer
rc = WNetCancelConnection2(DriveLetter & ":", 0, ForceDisconnect)
If rc = 0 Then
Return True
Else
Return False
End If
End Function
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!