如何检查C#中是否禁用了Windows帐户 [英] How to check that windows account is disabled in C#

查看:227
本文介绍了如何检查C#中是否禁用了Windows帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试检查窗口帐户是否在活动目录中被禁用,因此我尝试使用System.DirectoryServices.AccountManagement命名空间但找不到任何方法来检查帐户是否已禁用,与IsAccountLockedOut方法不同。





I am trying to check if window account is disabled or not in active directory, for this reason I tried System.DirectoryServices.AccountManagement namespace but could not find any method to check if account is disable unlike IsAccountLockedOut method.


PrincipalContext oPrincipalContext = GetPrincipalContext();
UserPrincipal oUserPrincipal =UserPrincipal.FindByIdentity(oPrincipalContext, sUserName);
oUserPrincipal.IsAccountLockedOut();

推荐答案





您可以通过选中 AuthenticablePrincipal.Enabled Property [ ^ ]



用法应该是这样的:

Hi,

You can check if the account is enabled for authentication by checking the AuthenticablePrincipal.Enabled Property[^]

Usage should be something like this:
using (PrincipalContext oPrincipalContext = GetPrincipalContext()){
    using (UserPrincipal oUserPrincipal = oPrincipalContext.FindByIdentity(oPrincipalContext, sUserName)){
        Console.Out.Write(oUserPrincipal.Enabled);
    }
}



...希望它有所帮助。


... hope it helps.


这篇关于如何检查C#中是否禁用了Windows帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆