共用方式為


啟用和停用使用者帳戶

若要啟用使用者帳戶,必須移除使用者物件之 userAccountControl 屬性的 ADS_UF_ACCOUNTDISABLE 旗標。如需 userAccountControl 屬性的詳細資訊,請參閱 MSDN Library (https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)) 中的<userAccountControl>或<User-Account-Control>。ADS_UF_ACCOUNTDISABLE 旗標是定義在 ADS_User_Flag_Enum 中。如需 ADS_User_Flag_Enum 列舉的詳細資訊,請參閱 MSDN Library (https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)) 中的<ADS_User_Flag_Enum>。

下列範例示範如何啟用使用者帳戶。

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();

下列範例示範如何停用使用者帳戶。

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();

請參閱

參考

System.DirectoryServices

概念

使用者管理

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.