How can we check disabled user in active directory?
i am working asp.net 2003. i use the following code. when the execution reaches to Dim obj As Object = entry.NativeObject then it will show the logon failure for the user. if it is disabled user. but if it is enabled user it will work fine.i want to check the idsabled user code. plese help me
Dim domainAndUsername As String = domain + "\" + username
Dim entry As New DirectoryEntry(_path, domainAndUsername, pwd)
Dim obj As Object = entry.NativeObject
Dim search = New DirectorySearcher(entry)
search.Filter = "(SAMAccountName=" + username + ")"
search.PropertiesToLoad.Add("cn")
search.PropertiesToLoad.Add("userAccountControl")
Dim result As SearchResult = search.FindOne()
If (result Is Nothing) Then Return False
' Update the new path to the user in the directory
_path = result.Path
_filterAttribute = result.Properties("cn")(0)
If Not _filterAttribute Is Nothing Then
Dim accountControl As Integer
accountControl = Convert.ToInt32(result.Properties("userAccountControl")(0))
Dim accountDisabled As Integer = Convert.ToInt32(UF_ACCOUNTDISABLE)
Dim flagExists As Integer = accountControl And accountDisabled
If flagExists > 0 Then
Throw New Exception("User Account Is Disabled")
Return False
Else
Return True
End If
End If