Home All Groups Group Topic Archive Search About

How do you uncheck "User cannot change password" and "Password never exipers" attributes in vb.net

Author
26 Sep 2006 3:08 PM
TheVillageCodingIdiot
Does anyone have any code that can do this. From what I understand,
these are flags in the "userAccountControl" properties but unsure how
to get it unchecked. Can anyone help?

Imports System
Imports System.DirectoryServices

Namespace ActiveDirectorySearch
    Public Class ADSearch
        Shared Sub main(ByVal strUserName As String)
            Dim Entry As New
DirectoryEntry("LDAP://server/dc=fully,dc=qualified,dc=domain")
            Dim DSESearcher As New DirectorySearcher(Entry)
            Dim strFilter As String = "(sAMAccountName=" & strUserName
& ")"
            Dim objUser As DirectoryEntry

            DSESearcher.SearchScope = SearchScope.Subtree
            DSESearcher.Filter = strFilter
            DSESearcher.PropertiesToLoad.Add("pwdLastSet")
            DSESearcher.PropertiesToLoad.Add("userAccountControl")


            Dim objResult As SearchResult = DSESearcher.FindOne

            If Not objResult Is Nothing Then

                objUser = objResult.GetDirectoryEntry

                objUser.Properties("pwdLastSet").Value = 0
                objUser.CommitChanges()

            End If

        End Sub
    End Class
End Namespace

AddThis Social Bookmark Button