Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Could anyone please help me on to get the locked users from active directory user group and get it unlocked by using c#.

Note: Only users from AD account not other AD objects.

I have tried this:

C#
string strUserName = o.SAMAccountName;

            using (var context = new PrincipalContext(ContextType.Domain))
            {
                using (var user1 = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, strUserName))
                {
                    if (user1.IsAccountLockedOut())//Getting below error here//
                    {
                        /* Button visible to Unlock user */
                    }
                    else
                    {
                        e.Row.Cells[ColumnUnlock].Controls.Clear();
                    }
                }
            }

am getting error "Object reference not set to an instance of object".

I tried with different method and getting different error, please help

Thanks in Advance
Posted
Updated 23-Dec-14 4:24am
v7

1 solution

This article should be helpfull: Howto: (Almost) Everything In Active Directory via C#[^]

Specifically Unlock a User Account[^]
 
Share this answer
 
Comments
Renjith_R 24-Dec-14 1:51am    
Thanks for the reply,I need to filter the locked users from the user group and unlock that users only. there is no way to find locked users from the user group here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900