bowlingbrad
Member
- Joined
- Feb 23, 2010
- Messages
- 6
- Programming Experience
- 1-3
I am creating a utility to unmap and map network drives on conference room computers. Everything works just fine except for my use of WNetAddConnection2 and WNetCancelConnection2. I seem to have pinpointed the problems to virtual server shares on an EMC Clarrion. My utility works just fine if the shares are pointing to physical servers. The virtual servers create errors.
WNetAddConnection2 returns error 1219
WNetCancelConnection2 returns error 2250
I think Cancel works even though 2250 is returned.
WNetAddConnection2 returns error 1219
WNetCancelConnection2 returns error 2250
I think Cancel works even though 2250 is returned.
VB.NET:
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
Public Const ForceDisconnect As Integer = 1
Public Const RESOURCETYPE_DISK As Long = &H1
Public Function MapDrive(ByVal DriveLetter As String, ByVal UNCPath As String) As Boolean
Dim nr As NETRESOURCE
Dim strUsername As String
Dim strPassword As String
nr = New NETRESOURCE
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter & ":"
nr.dwType = RESOURCETYPE_DISK
strUsername = tbUsername.Text
strPassword = tbPass.Text
Dim result As Integer
result = WNetAddConnection2(nr, strPassword, strUsername, RESOURCETYPE_DISK)
If result = 0 Then
Return True
ElseIf result = 85 Then
MsgBox("Error: " & result & vbLf & "Drive: " & DriveLetter & " ALREADY EXISTS!", MsgBoxStyle.Exclamation)
Else
MsgBox("Error: " & result & vbLf & "Drive: " & DriveLetter & " NOT CONNECTED!", MsgBoxStyle.Exclamation)
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 Or rc = 2250 Then
Return True
Else
MsgBox("rc= " & rc & vbLf & "Drive letter " & DriveLetter & " NOT DISCONNECTED!")
Return False
End If
End Function