WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Detect Disabled Accounts


Question:

Is there a relatively easy way to detect if an AD user account is disabled?

Answer:

; The tech db article is saying do the following and
; it gets a list of all disabled users.

AddExtender("wwads44i.dll")

; Search the domain.
; Note: server name used here (shamrock) but not necessary
; if computer joined to the domain.
sDomain = "LDAP://shamrock/dc=jclass,dc=org"

; Disabled accounts have the second bit (2) of the
; userAccountControl property set.
sFilter = "(&(objectCategory=person)(objectClass=person)(userAccountControl:1.2.840.113556.1.4.803:=2))"

lDisabled = dsFindPath(sDomain, sFilter)

Message("Disabled users", lDisabled)

; To get the status of known user account
; check the bit directly.

sUser = "LDAP://shamrock/cn=Homer Simpson,cn=users,dc=jclass,dc=org"
nStatus = dsGetProperty(sUser, "userAccountControl")

If nStatus & 2   ; Note: bitwise AND
   sText = "Is disabled"
Else
   sText = "Is enabled"
EndIf

Message(sUser, sText)


Article ID:   W16794
File Created: 2007:07:03:14:26:18
Last Updated: 2007:07:03:14:26:18