How to determine if user account is enabled or disabled

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

    Not that anyone asked, but here's a java version (since I ended up here looking for one). Null checking is left as an exercise for the reader.

    private Boolean isActive(SearchResult searchResult) {
        Attribute userAccountControlAttr = searchResult.getAttributes().get("UserAccountControl");
        Integer userAccountControlInt = new Integer((String) userAccoutControlAttr.get());
        Boolean disabled = BooleanUtils.toBooleanObject(userAccountControlInt & 0x0002);
        return !disabled;
    }
    

提交回复
热议问题