find if user account is enabled or disabled in AD

前端 未结 2 1502
情书的邮戳
情书的邮戳 2021-02-20 05:37

I need to find if user account is enabled or disabled in AD.

i Cant find the flag or property \"userAccountControl\". is this can be achieved using USER

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-20 06:07

    If you just need to find out if user is enabled or disable you can do it a bit simpler with the following:

    PrincipalContext context = new PrincipalContext(ContextType.Domain);
    UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, searchTextBox.Text.Trim());
    
    if(user.Enabled == true) MessageBox.Show("Account enabled!");
    else MessageBox.Show("Account disabled!");
    

提交回复
热议问题