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.

AD Locked Account Problem


Question:

I have been attempting to debug an issue where the dsGetProperty function is returning an 'invalid' value when trying to query the UserAccountControl property.

Background:

An AD user account is forced into a 'Locked' state by forcing multiple failed logon attempts.

The AD GUI shows that user accounts UserAccountControl property is LOCKED.

Then a script is ran under a Domain Admin account the queries that property using dsGetProperty. dsGetProperty returns 512 which indicates a NORMAL account. (When it should be indicating it is LOCKED).

That same script then calls wntUserGetDat which returns 529. This indicates that the wntUserGetDat function can see that account is locked.

Do you have any ideas why the dsgetProperty function is not successfully picking up the locked state on that account?

Answer:

Here is the response I received from the developers:
‘It is not a bug in the extender. It is just reporting what Active Directory is telling it. Active directory has a different mechanism for handling locked out users.

I think you need to use the "lockoutTime" property. For example to find all users that may be locked

 ; Do the search.
 lResults = dsFindPath(sServerPath, "(&(&(objectCategory=person)(objectClass=user))(lockoutTime>=1))")
 
or to clear a lock on a particular user
 ; Clear the lockout by setting the property to zero.
 dsSetProperty(sUserPath,  "lockoutTime", 0)
 
This is from memory and have not run any of this but I think this is how it works.

I think if you were to query the user account using the WinNT name space and the "userFlags" property you would get the same result as you get with the NT extender function wntUserGetDat. Again this is from memory....’

I also did some searches at http://groups.google.com and found a few threads that confirm that if the lockoutTime property is not present or 0 then the account is not locked out and <> 0 if it is locked out.

http://groups-beta.google.com/group/microsoft.public.adsi.general/messages/8f3a4ef507075cc6,3fcb0e7ec2c4daaa,b5a19cf7cf227c16,a13b88205d48dd7f,1cd6d22a95dfd907,0bb08bf0d94463ef,a636f16f3bbfb329,71ff13e08fc963cd,dfb29c831c826e16,e86a9f12b50c9a17?thread_id=108ceebf8c78f1f&view=thread&noheader=1&q=AD+Account+Locked+property#doc_a13b88205d48dd7f

http://groups-beta.google.com/group/microsoft.public.adsi.general/messages/3f1863c877ebd386,90b30bac7da96933,2fd325b03a9e8880,2cfd0e828327a99e,a9895f2861bdb4be,79b9a08406b4ba27,6a61148d64baff98?thread_id=835c9204f64eb3d6&view=thread&noheader=1&q=AD+Account+Locked+property#doc_6a61148d64baff98

http://groups-beta.google.com/group/microsoft.public.adsi.general/messages/e2898b433f9f41e8,1a0c8d74cae6fd27,9c6a3f5498e283a8,1cf00097f89a5708,82581b99a14fcc8d,f02d545371f8ed88,877edf8305940f1d?thread_id=daa63dc767ebf387&view=thread&noheader=1&q=AD+Account+Locked+property#doc_877edf8305940f1d

Give the above dsFindPath code a try and let me know if it resolves the issue.

User Reply:

I got a chance to write a quick stub program that used your recommendations. It works. As I stated, locking the account is not reflected in userAccountControl. But as your developers recalled, lockoutTime changed when I locked the account. I found that it will contain the time the user locked their account out in CCYY:MM:DD:hh:mm:ss format (at least that is how WinBatch displays it in a message). Setting that same property to zero also unlocked the account, as you stated.

Here is the code that works:

;
;   Check if User Account is Locked, if so then Unlock the Account.
;
;
AddExtender("WWADS34I.DLL")
lockoutTime     = "lockoutTime"
Server          = dsGetProperty("LDAP://rootDSE"  , "serverName")
Server          = ItemExtract(1, Server, ",")
Server          = ItemExtract(2, Server, "=")
;
UserName        = "TESTUSER"
:LoopAgain
UserName        = AskLine("AcctLock", "Enter LoginID:", UserName)
sObjectPath2    = StrCat("LDAP://", Server, "/CN=", UserName, ",OU=Domain Users,DC=dummy,DC=com")
;
flags           = dsGetProperty(sObjectPath2, lockoutTime)

If (flags == 0)
    Message("AcctLock", "Account %UserName% is not locked.")  
Else    
    flags       = 0    ; Unlock
    dsSetProperty(sObjectPath2, lockoutTime, flags)             
    Message("AcctLock lockoutTime", StrCat(UserName, " has been unlocked") )
EndIf
;
Exit

Case: closed.

Thanks much for your help, once again!


Article ID:   W16788
File Created: 2007:07:03:14:26:16
Last Updated: 2007:07:03:14:26:16