How to determine if user account is enabled or disabled

后端 未结 4 753
野性不改
野性不改 2020-12-04 13:54

I am throwing together a quick C# win forms app to help resolve a repetitive clerical job.

I have performed a search in AD for all user accounts and am adding them t

4条回答
  •  北海茫月
    2020-12-04 14:26

    I came here looking for an answer, but it was only for DirectoryEntry. So here is a code that works for SearchResult / SearchResultCollection, for people who had the same problem:

    private bool checkIfActive(SearchResult sr)
    {
        var vaPropertiy = sr.Properties["userAccountControl"];
    
        if (vaPropertiy.Count > 0) 
        {
            if (vaPropertiy[0].ToString() == "512" || vaPropertiy[0].ToString() == "66048") 
            {
                return true;
            } 
            
            return false;
        }
    
        return false;
    }
    

提交回复
热议问题