CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2010
    Posts
    7

    Reseting a users password via Active Directory using Visual Basic 2010..

    Hi Guys im writing a little app to enable authorised staff to reset student passwords but having a few issues. . I am no expert and am now stuck!

    The following code does not seem to error but also does not reset the password!

    _________________________

    Private Sub bt_pwd_reset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt_pwd_reset.Click

    tb_newpwd1.Text = GenPassword.ToString

    Try

    Dim username As String = TUserName.Text
    Dim de As DirectoryEntry = New DirectoryEntry()
    de.Path = "LDAP://10.33.0.25/OU=Staff_Users;dc=domain,dc=domain,dc=internal"

    de.Username = "DOMAIN\username-admin"
    de.Password = "domainpassword"

    de.AuthenticationType = AuthenticationTypes.Secure

    Dim deSearch As DirectorySearcher = New DirectorySearcher(de)
    deSearch.SearchRoot = de
    deSearch.Filter = ("(sAMAccountName=" & username & ")")
    Dim results As SearchResultCollection = deSearch.FindAll()
    If results.Count = 0 Then
    message.Text = "Can not locate user name: " & username
    message.Visible = True
    Exit Sub
    End If



    With de
    .InvokeSet("serPassword", "Password123")
    ' .Invoke("SetPassword", Password123)
    .CommitChanges()
    End With

    de.Close()

    Catch ex As Exception
    message.Text = ex.ToString
    End Try
    lb_bigpwd.Text = tb_newpwd1.Text
    End Sub

    ______________________________________________

    Any help on this would be great!!

    Thanks in advance
    Anthony

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Reseting a users password via Active Directory using Visual Basic 2010..

    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured