Change Password (Visual Basic)

This code can be found in Chapter 28 of Active Directory, 3rd Edition

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the Visual Basic code from this site.

' From the book "Active Directory, Third Edition" 
' ISBN: 0-596-10173-2

Private Sub cmdChangePassword_Click()
   
Dim objUser As IADsUser
   
If txtUsername.Text <> "" Then
  If txtPass1.Text = txtPass2.Text Then
    Set objUser = GetObject("LDAP://cn=" + txtUsername.Text _
      + ",cn=Users,dc=mycorp,dc=com")
  
    objUser.SetPassword txtPass1.Text
    objUser.pwdLastSet = 0
	objUser.lockoutTime = 0
    objUser.SetInfo
   

    'Reset everything
    txtUsername.Text = ""
    txtPass1.Text = ""
    txtPass2.Text = ""
  
    MsgBox "Password changed!"
  Else
    MsgBox "Passwords are not the same, please try again!"
  End If
Else
  MsgBox "A username must be specified!"
End If

This code has been viewed 6695 times.

New from the creators of TechTasks.com: StatSheet.com