This documentation is archived and is not being maintained.

AuthenticablePrincipal.UnlockAccount Method

Unlocks the account if it is currently locked out.

Namespace:  System.DirectoryServices.AccountManagement
Assembly:  System.DirectoryServices.AccountManagement (in System.DirectoryServices.AccountManagement.dll)

public void UnlockAccount()

ExceptionCondition
PrincipalOperationException

Throws an exception if the caller does not have appropriate rights.

PrincipalOperationException

An exception occurred when saving the changes to the store.

The following example code connects to the LDAP domain "fabrikam.com" with the username (administrator) and password (SecretPwd123) initialized in the PrincipalContext constructor.

A search is performed to find the user with name "John Smith" under the container specified in the PrincipalContext constructor: "CN=Users,DC=fabrikam,DC=com." If the user is found, a check is performed to determine whether this user's account has been locked out. If the account has been locked out, the code example unlocks the account.

PrincipalContext ctx = new PrincipalContext(ContextType.Domain, 
                                         "fabrikam.com", 
                                         "CN=Users,DC=fabrikam,DC=com", 
                                         "administrator", 
                                         "SecretPwd123");
        
UserPrincipal usr = UserPrincipal.FindByIdentity(ctx, "John Smith");
if (usr != null)
{
    if (usr.IsAccountLockedOut())
        usr.UnlockAccount();

    usr.Dispose();
}
ctx.Dispose(); 

.NET Framework

Supported in: 4, 3.5

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: