简体   繁体   中英

c# check if a windows account is locked out in a specific domain

I'm trying to do something that I don't even know if it is possible. I have a web application based on C# that runs on a specific server. I want to build a code where the user introduces the domain where the app runs (this server depends on the client, for each client it runs on different servers obviously) and the app returns the local windows user accounts of that domain and information saying if the users are locked out or not.

I've tried to use Win32_UserAccount but it seems to get the users of the network I'm currently using.

Is this possible to do?

Thank you so much Regards, Flávio Justino

Try

using(PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "domain"))
{
        using(UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, "username"))
        {
            usr.IsAccountLockedOut(); //Gets if account is locked out
        }   
}

You need to add dpendency System.DirectoryServices.AccountManagement.dll for the above code to work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM