Good Question, but I dont think so. The code for that form is listed below.
Thanks,
Jason
Imports System.Runtime.InteropServices
Public Class frmMapDrives
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
<StructLayout(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) As Boolean
Dim nr As NETRESOURCE
Dim strUsername As String
Dim strPassword As String
Dim result As Integer
nr = New NETRESOURCE
Try
nr.lpRemoteName = UNCPath
nr.lpLocalName = DriveLetter & ":"
strUsername = txtUserName.Text '"username@domain.com" 'Nothing '(add parameters to pass this if necessary)
strPassword = txtPassword.Text '"password" 'Nothing '(add parameters to pass this if necessary)
nr.dwType = RESOURCETYPE_DISK
result = WNetAddConnection2(nr, strPassword, strUsername, 0)
Catch
result = 1
End Try
If result = 0 Or result = 85 Then
Return True
Else
'If result = 1326 Then
' MsgBox("Error: Logon Failure" & vbCrLf & "Carefully enter your admin credentials and try again.")
' Return False
'End If
MsgBox(nr.lpRemoteName & " Failed to Map to " & nr.lpLocalName)
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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMapDrives.Click
If MapDrives() = True Then
MsgBox("DCLI | DSVR | QSVR Have Been Mapped!")
Me.Close()
Else
MsgBox("DCLI | DSVR | QSVR Did Not Map." & vbCrLf & "Check your credentials and try again.")
End If
End Sub
'Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' UnMapDrives()
'End Sub
Private Function MapDrives() As Boolean
Dim blnSuccess As Boolean = True
If MapDrive(My.Settings.DriveLetterToDCLI, My.Settings.UNCPathToDCLI) Then
Else
blnSuccess = False
End If
If MapDrive(My.Settings.DriveLetterToDSVR, My.Settings.UNCPathToDSVR) Then
Else
blnSuccess = False
End If
If MapDrive(My.Settings.DriveLetterToQSVR, My.Settings.UNCPathToQSVR) Then
Else
blnSuccess = False
End If
Return blnSuccess
End Function
Public Function UnMapDrives() As Boolean
UnMapDrive(My.Settings.DriveLetterToDCLI)
UnMapDrive(My.Settings.DriveLetterToDSVR)
UnMapDrive(My.Settings.DriveLetterToQSVR)
MsgBox("DCLI | DSVR | QSVR Have Been Un-Mapped!")
End Function
Private Sub btnHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHelp.Click
ToolTip1.SetToolTip(btnHelp, "Roadshow Watcher needs to map the network drives: DCLI, DSVR, and QSVR." & vbCrLf & "Please enter your admin credentials below using the 'username@fsproduce.com' convention and press the Map Drives button to continue.")
End Sub
Private Sub frmMapDrives_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.txtUserName.Focus()
Me.Focus()
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
End
End Sub
End Class
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129:





by: jpaulinoPosted on 2009-10-22 at 06:15:27ID: 25633739
Do you have something in the frmMapDrives that could make the form loses the focus ?