Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Forgot Active Directory Password Script in .NET
- Private Function ChangeLocalUserPassword(ByVal User As String, ByVal Pass As String) As Boolean
- Dim pinger As New Net.NetworkInformation.Ping
- Dim usr As DirectoryEntry
- _de = GetDirectoryEntry()
- If _de Is Nothing Then
- 'couldn't connect or find account
- MsgBox("_de is Nothing")
- Return False
- End If
- Try
- usr = _de.Children.Find("CN=" & User, "User")
- Catch ex As Exception
- MsgBox("User could not be found!")
- Return False
- End Try
- Try
- usr.Invoke("SetPassword", Pass)
- usr.CommitChanges()
- usr.Properties("LockOutTime").Value = 0
- usr.CommitChanges()
- Catch ex As Exception
- MsgBox("Error is " & ex.Message)
- Return False
- End Try
- End Function
- Private Function GetDirectoryEntry() As DirectoryEntry
- Dim dirEntry As DirectoryEntry = New DirectoryEntry()
- dirEntry.Path = "LDAP://<SERVER>/ou=<OU>,dc=<DOMAIN>"
- dirEntry.Username = "<DOMAIN>Administrator"
- dirEntry.Password = "<PASSWORD>"
- Return dirEntry
- End Function
Add Comment
Please, Sign In to add comment