Guest User

Untitled

a guest
Oct 11th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. Public Sub Find(ByVal ServName As Object)
  2. Try
  3.  
  4. Dim DCNames(15), logincred, loginpass, Domain As String
  5. Dim lvl As System.Windows.Forms.ListViewItem
  6. Dim DCL As New UDCLC 'delegate of the login credintials
  7. Dim DCLDel As UDCLC.UDCL_Del = AddressOf DCL.UDCL 'delegate of the login credintials
  8. Dim Debug As New Debugged 'Delegate to update MainForm.Errbox with errors.
  9. Dim ErxB_Del As Debugged.ErxB_Del = AddressOf Debug.UErb 'Delegate to update MainForm.Errbox with errors.
  10. Dim SevName = CStr(Servname)
  11. DCNames(0) = SevName
  12. loginpass = Nothing
  13. logincred = Nothing
  14. Domain = Nothing
  15.  
  16. If ConnInfo.D1 = True Then
  17. logincred = USN.Dom1NetCred.UserName
  18. loginpass = USN.Dom1NetCred.Password
  19. Domain = USN.Dom1NetCred.Domain
  20. Else If ConnInfo.DA = True Then
  21. logincred = USN.DomANetCred.UserName
  22. loginpass = USN.DomANetCred.Password
  23. Domain = USN.DomANetCred.Domain
  24. End If
  25.  
  26. Dim ConServ As New System.DirectoryServices.AccountManagement.PrincipalConText(System.DirectoryServices.AccountManagement.ConTextType.Domain, DCnames(0) & "." & Domain, logincred, loginpass)
  27. Dim FoundUser = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(ConServ,System.DirectoryServices.AccountManagement.IdentityType.SamAccountName,ConnInfo.Filed)
  28.  
  29. 'FinFo.Filter = ("(sAMAccountName=" & ConnInfo.Filed & ")")
  30. 'Dim GetF As System.DirectoryServices.SearchResult = FinFo.FindOne
  31.  
  32. If ConnInfo.D1 = True Then
  33. DCNames(1) = SevName.Remove(0,1)
  34. DCNames(1) = DCNames(1).Remove(3,6)
  35. Else If ConnInfo.DA = True Then
  36. DCNames(1) = SevName.Remove(0,1)
  37. If DCNames(1).Length = 9 Then
  38. DCNames(1) = DCNames(1).Remove(3,6)
  39. Else
  40. DCNames(1) = DCNames(1).Remove(3,4)
  41. End If
  42. End If
  43.  
  44. If FoundUser.IsAccountLockedOut = True Then
  45. DCNames(2) = FoundUser.IsAccountLockedOut.ToString
  46. Else
  47. DCNames(2) = FoundUser.IsAccountLockedOut.ToString
  48. End If
  49.  
  50. If FoundUser.Enabled.HasValue Then DCNames(3) = FoundUser.Enabled.Value.ToString
  51.  
  52. If FoundUser.BadLogonCount = Nothing Then
  53. DCNames(4) = "0"
  54. Else
  55. DCNames(4) = FoundUser.BadLogonCount.ToString
  56. End If
  57.  
  58. If FoundUser.LastBadPasswordAttempt.HasValue Then
  59. DCNames(5) = FoundUser.LastBadPasswordAttempt.Value.ToLocalTime
  60. Else
  61. DCNames(5) = "-"
  62. End If
  63.  
  64. If FoundUser.AccountLockoutTime.HasValue Then
  65. DCNames(6) = FoundUser.AccountLockoutTime.Value.ToLocalTime
  66. Else
  67. DCNames(6) = "-"
  68. End If
  69.  
  70. If FoundUser.LastPasswordSet.HasValue Then
  71. DCNames(7) = FoundUser.LastPasswordSet.Value.ToLocalTime
  72. Else
  73. DCNames(7) = "Password Must Change"
  74. End If
  75.  
  76. If FoundUser.LastLogon.HasValue Then
  77. DCNames(8) = FoundUser.LastLogon.Value.ToLocalTime
  78. Else
  79. DCNames(8) = "-"
  80. End If
  81.  
  82. If FoundUser.Description Is Nothing Then
  83. Else
  84. DCNames(9) = FoundUser.Description.ToString
  85. End If
  86.  
  87. lvl = New System.Windows.Forms.ListViewItem(DCNames)
  88.  
  89. Me.DClist.Invoke(DCLDel,lvl)
  90.  
  91. 'ConServ = Nothing
  92. 'FoundUser = Nothing
  93. 'GetF = Nothing
  94. ConServ.dispose
  95. FoundUser.dispose
  96.  
  97. Catch Ex As Exception
  98. Dim Debug As New Debugged
  99. Dim ErxB_Del As Debugged.ErxB_Del = AddressOf Debug.UErb
  100. Dim ExpBase = Ex.GetBaseException
  101. Dim DCNames(9) As String
  102. Dim lvl As System.Windows.Forms.ListViewItem
  103. Dim DCL As New UDCLC
  104. Dim DCLDel As UDCLC.UDCL_Del = AddressOf DCL.UDCL
  105.  
  106. Select Case Ex.Message
  107. Case "Object reference not set to an instance of an object."
  108. Me.ErrBox.BeginInvoke(ErxB_Del, (vbNewLine & System.DateTime.Now & ": User Not Found on " & USN.DomANetCred.Domain))
  109. Case "The server could not be contacted."
  110. Me.ErrBox.BeginInvoke(ErxB_Del, (vbNewLine & System.DateTime.Now & ": " & ServName & ": Server could not be contacted."))
  111. DCNames(0) = ServName.ToString
  112. DCNames(1) = "-"
  113. DCNames(2) = "-"
  114. DCNames(3) = "-"
  115. DCNames(4) = "-"
  116. DCNames(5) = "DC Unavailable"
  117. DCNames(6) = "DC Unavailable"
  118. DCNames(7) = "DC Unavailable"
  119. DCNames(8) = "DC Unavailable"
  120. lvl = New System.Windows.Forms.ListViewItem(DCNames)
  121. Me.dclist.Invoke(DCLDel,lvl)
  122. Case Else
  123. Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__Message:" & Ex.Message.ToString))
  124. Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__Source:" & Ex.Source.ToString))
  125. Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__StackTrace:" & Ex.StackTrace.ToString))
  126. Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__TargetSite:" & Ex.TargetSite.ToString))
  127. If Ex.InnerException IsNot Nothing Then Me.ErrBox.Invoke(ErxB_Del, (vbNewLine & "__InnerException:" & Ex.InnerException.Message.ToString))
  128. End Select
  129. Finally
  130. End Try
  131. System.Threading.Thread.CurrentThread.Abort()
  132. End Sub
Add Comment
Please, Sign In to add comment