次の方法で共有


Enabling and Disabling the User Account

To enable a user account, you must remove the ADS_UF_ACCOUNTDISABLE flag from the userAccountControl attribute of the user object. For more information about the userAccountControl attribute, see "userAccountControl" or "User-Account-Control" in the MSDN Library at https://go.microsoft.com/fwlink/?LinkID=27252. The ADS_UF_ACCOUNTDISABLE flag is defined in the ADS_User_Flag_Enum. For more information about ADS_User_Flag_Enum enumeration, see "ADS_User_Flag_Enum" in the MSDN Library at https://go.microsoft.com/fwlink/?LinkID=27252.

The following example shows how to enable a user account.

DirectoryEntry usr = 
    new DirectoryEntry("LDAP://CN=New User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val & 
    ~(int)ActiveDs.ADS_USER_FLAG.ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();

The following example shows how to disable a user account.

DirectoryEntry usr = 
    new DirectoryEntry("LDAP://CN=Old User,CN=users,DC=fabrikam,DC=com");
int val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    (int)ActiveDs.ADS_USER_FLAG.ADS_UF_ACCOUNTDISABLE;
usr.CommitChanges();

See Also

Reference

System.DirectoryServices

Concepts

User Management

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.