C# 验证输入的Account是不是域合法的用户,组或机器。(User, Group, Machine)

            Principal accountInfo;            
            using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, domain))
            {
                accountInfo = Principal.FindByIdentity(ctx, name);
            }

            if (accountInfo == null)
            {
                return false;
            }

       AccountType accountType
if (accountInfo is UserPrincipal) { accountType = AccountType.User; } else if (accountInfo is GroupPrincipal) { accountType = AccountType.Group; } else { accountType = AccountType.Machine; }

  

posted on 2012-10-22 17:21  seacryfly  阅读(571)  评论(0编辑  收藏  举报