How to determine if user account is enabled or disabled

后端 未结 4 766
野性不改
野性不改 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:49

    this code here should work...

    private bool IsActive(DirectoryEntry de)
    {
      if (de.NativeGuid == null) return false;
    
      int flags = (int)de.Properties["userAccountControl"].Value;
    
      return !Convert.ToBoolean(flags & 0x0002);
    }
    

提交回复
热议问题