Lock/unlock account-Active Directory

Source: Internet
Author: User

Lock/unlockAccount-Active Directory

 

Written by: Rickie Lee (http://www.cnblogs.com/rickie)

Determine whether the account is locked or not based on the isaccountlocked attribute. Because LDAP provider does not support the isaccountlocked attribute, winnt provider is used here: (Note that the provider identifier is case sensitive)

 

1.ObtainIsaccountlockedAttribute to determine whether or notLock/unlock

String struser = @ "winnt: // mydomain/" + domainuserid;

Directoryentry de = new directoryentry (struser );

Object objusr = de. nativeobject;

Type T = objusr. GetType ();

 

Bool boollocked = (bool) T. invokemember ("isaccountlocked", bindingflags. getproperty, null, objusr, null );

 

Boollocked = true indicates that the account is locked.

= False indicates that the account is unlocked.

 

 

2. Lock/unlock account

// Unlock an account

T. invokemember ("isaccountlocked", bindingflags. setproperty, null, objusr, new object [] {"false "});

 

// Lock an account

T. invokemember ("isaccountlocked", bindingflags. setproperty, null, objusr, new object [] {"true "});


De. commitchanges ();

 

References:

1. Rickie, update the gadgets for Active Directory/exchange Address Book, http://www.cnblogs.com/rickie/archive/2005/06/29/183043.html

2. Craig Aroa, adhelper-An Active Directory class,

Http://www.c-sharpcorner.com/Code/2002/Sept/ADClass.asp

3. Rickie, User Authentication Based on Active Directory, http://www.cnblogs.com/rickie/archive/2005/06/30/183700.html

4. Rickie, getting user information from Active Directory, http://www.cnblogs.com/rickie/archive/2005/07/01/184289.html

5. Rickie, updates user information in Active Directory, http://www.cnblogs.com/rickie/archive/2005/07/02/184927.html

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.