Guest User

Untitled

a guest
Sep 1st, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. Forgot Active Directory Password Script in .NET
  2. Private Function ChangeLocalUserPassword(ByVal User As String, ByVal Pass As String) As Boolean
  3. Dim pinger As New Net.NetworkInformation.Ping
  4. Dim usr As DirectoryEntry
  5. _de = GetDirectoryEntry()
  6.  
  7. If _de Is Nothing Then
  8. 'couldn't connect or find account
  9. MsgBox("_de is Nothing")
  10. Return False
  11. End If
  12. Try
  13. usr = _de.Children.Find("CN=" & User, "User")
  14. Catch ex As Exception
  15. MsgBox("User could not be found!")
  16. Return False
  17. End Try
  18. Try
  19. usr.Invoke("SetPassword", Pass)
  20. usr.CommitChanges()
  21. usr.Properties("LockOutTime").Value = 0
  22. usr.CommitChanges()
  23. Catch ex As Exception
  24. MsgBox("Error is " & ex.Message)
  25. Return False
  26. End Try
  27.  
  28. End Function
  29.  
  30. Private Function GetDirectoryEntry() As DirectoryEntry
  31. Dim dirEntry As DirectoryEntry = New DirectoryEntry()
  32. dirEntry.Path = "LDAP://<SERVER>/ou=<OU>,dc=<DOMAIN>"
  33. dirEntry.Username = "<DOMAIN>Administrator"
  34. dirEntry.Password = "<PASSWORD>"
  35. Return dirEntry
  36. End Function
Add Comment
Please, Sign In to add comment