Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Sub Find(ByVal ServName As Object)
- Try
- Dim DCNames(15), logincred, loginpass, Domain As String
- Dim lvl As System.Windows.Forms.ListViewItem
- Dim DCL As New UDCLC 'delegate of the login credintials
- Dim DCLDel As UDCLC.UDCL_Del = AddressOf DCL.UDCL 'delegate of the login credintials
- Dim Debug As New Debugged 'Delegate to update MainForm.Errbox with errors.
- Dim ErxB_Del As Debugged.ErxB_Del = AddressOf Debug.UErb 'Delegate to update MainForm.Errbox with errors.
- Dim SevName = CStr(Servname)
- DCNames(0) = SevName
- loginpass = Nothing
- logincred = Nothing
- Domain = Nothing
- If ConnInfo.D1 = True Then
- logincred = USN.Dom1NetCred.UserName
- loginpass = USN.Dom1NetCred.Password
- Domain = USN.Dom1NetCred.Domain
- Else If ConnInfo.DA = True Then
- logincred = USN.DomANetCred.UserName
- loginpass = USN.DomANetCred.Password
- Domain = USN.DomANetCred.Domain
- End If
- Dim ConServ As New System.DirectoryServices.AccountManagement.PrincipalConText(System.DirectoryServices.AccountManagement.ConTextType.Domain, DCnames(0) & "." & Domain, logincred, loginpass)
- Dim FoundUser = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(ConServ,System.DirectoryServices.AccountManagement.IdentityType.SamAccountName,ConnInfo.Filed)
- 'FinFo.Filter = ("(sAMAccountName=" & ConnInfo.Filed & ")")
- 'Dim GetF As System.DirectoryServices.SearchResult = FinFo.FindOne
- If ConnInfo.D1 = True Then
- DCNames(1) = SevName.Remove(0,1)
- DCNames(1) = DCNames(1).Remove(3,6)
- Else If ConnInfo.DA = True Then
- DCNames(1) = SevName.Remove(0,1)
- If DCNames(1).Length = 9 Then
- DCNames(1) = DCNames(1).Remove(3,6)
- Else
- DCNames(1) = DCNames(1).Remove(3,4)
- End If
- End If
- If FoundUser.IsAccountLockedOut = True Then
- DCNames(2) = FoundUser.IsAccountLockedOut.ToString
- Else
- DCNames(2) = FoundUser.IsAccountLockedOut.ToString
- End If
- If FoundUser.Enabled.HasValue Then DCNames(3) = FoundUser.Enabled.Value.ToString
- If FoundUser.BadLogonCount = Nothing Then
- DCNames(4) = "0"
- Else
- DCNames(4) = FoundUser.BadLogonCount.ToString
- End If
- If FoundUser.LastBadPasswordAttempt.HasValue Then
- DCNames(5) = FoundUser.LastBadPasswordAttempt.Value.ToLocalTime
- Else
- DCNames(5) = "-"
- End If
- If FoundUser.AccountLockoutTime.HasValue Then
- DCNames(6) = FoundUser.AccountLockoutTime.Value.ToLocalTime
- Else
- DCNames(6) = "-"
- End If
- If FoundUser.LastPasswordSet.HasValue Then
- DCNames(7) = FoundUser.LastPasswordSet.Value.ToLocalTime
- Else
- DCNames(7) = "Password Must Change"
- End If
- If FoundUser.LastLogon.HasValue Then
- DCNames(8) = FoundUser.LastLogon.Value.ToLocalTime
- Else
- DCNames(8) = "-"
- End If
- If FoundUser.Description Is Nothing Then
- Else
- DCNames(9) = FoundUser.Description.ToString
- End If
- lvl = New System.Windows.Forms.ListViewItem(DCNames)
- Me.DClist.Invoke(DCLDel,lvl)
- 'ConServ = Nothing
- 'FoundUser = Nothing
- 'GetF = Nothing
- ConServ.dispose
- FoundUser.dispose
- Catch Ex As Exception
- Dim Debug As New Debugged
- Dim ErxB_Del As Debugged.ErxB_Del = AddressOf Debug.UErb
- Dim ExpBase = Ex.GetBaseException
- Dim DCNames(9) As String
- Dim lvl As System.Windows.Forms.ListViewItem
- Dim DCL As New UDCLC
- Dim DCLDel As UDCLC.UDCL_Del = AddressOf DCL.UDCL
- Select Case Ex.Message
- Case "Object reference not set to an instance of an object."
- Me.ErrBox.BeginInvoke(ErxB_Del, (vbNewLine & System.DateTime.Now & ": User Not Found on " & USN.DomANetCred.Domain))
- Case "The server could not be contacted."
- Me.ErrBox.BeginInvoke(ErxB_Del, (vbNewLine & System.DateTime.Now & ": " & ServName & ": Server could not be contacted."))
- DCNames(0) = ServName.ToString
- DCNames(1) = "-"
- DCNames(2) = "-"
- DCNames(3) = "-"
- DCNames(4) = "-"
- DCNames(5) = "DC Unavailable"
- DCNames(6) = "DC Unavailable"
- DCNames(7) = "DC Unavailable"
- DCNames(8) = "DC Unavailable"
- lvl = New System.Windows.Forms.ListViewItem(DCNames)
- Me.dclist.Invoke(DCLDel,lvl)
- Case Else
- Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__Message:" & Ex.Message.ToString))
- Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__Source:" & Ex.Source.ToString))
- Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__StackTrace:" & Ex.StackTrace.ToString))
- Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__TargetSite:" & Ex.TargetSite.ToString))
- If Ex.InnerException IsNot Nothing Then Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__InnerException:" & Ex.InnerException.Message.ToString))
- End Select
- Finally
- End Try
- System.Threading.Thread.CurrentThread.Abort()
- End Sub
Add Comment
Please, Sign In to add comment