设置用户帐户标志

本主题包含设置不同用户标志的代码示例。它使用 DirectoryEntry 对象的 Properties 属性访问 User-Account-Control 特性,以设置在 ADS_USER_FLAG_ENUM 枚举中定义的标志。有关 User-Account-Control 属性的详细信息,请参阅 MSDN Library(网址为 https://go.microsoft.com/fwlink/?LinkID=27252)中的主题 User-Account-Control。有关 ADS_USER_FLAG_ENUM 枚举的详细信息,请参阅 MSDN Library(网址为 https://go.microsoft.com/fwlink/?LinkID=27252)中的主题 ADS_USER_FLAG_ENUM。

以下示例说明如何设置 DirectoryEntry 对象 usr 的不同属性。因为此代码访问 System.DirectoryServices 命名空间中的对象,所以在应用程序中使用此代码时,在添加对解决方案资源管理器中 System.DirectoryServices 命名空间的引用。

下面的示例说明如何要求将 SmartCard 用于交互登录。

[Visual Basic]

Const ADS_UF_SMARTCARD_REQUIRED As Integer = &H40000
Val = Fix(usr.Properties("userAccountControl").Value)
usr.Properties("userAccountControl").Value = val Or _
      ADS_UF_SMARTCARD_REQUIRED
usr.CommitChanges()
const int ADS_UF_SMARTCARD_REQUIRED = 0x40000;
val = (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    ADS_UF_SMARTCARD_REQUIRED;
usr.CommitChanges();

下面的示例说明如何设置帐户以使用 DES 加密类型。

[Visual Basic]

Const ADS_UF_USE_DES_KEY_ONLY As Integer = &H200000
Val = Fix(usr.Properties("userAccountControl").Value)
usr.Properties("userAccountControl").Value = val Or _
      ADS_UF_USE_DES_KEY_ONLY
usr.CommitChanges()
const int ADS_UF_USE_DES_KEY_ONLY=0x200000;
val= (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    ADS_UF_USE_DES_KEY_ONLY;
usr.CommitChanges();

下面的示例说明如何设置该帐户,使其成为受信任帐户以用于委托。

[Visual Basic]

Const ADS_UF_TRUSTED_FOR_DELEGATION As Integer = &H80000
Val = Fix(usr.Properties("userAccountControl").Value)
usr.Properties("userAccountControl").Value = val Or _
      ADS_UF_TRUSTED_FOR_DELEGATION
usr.CommitChanges()
const int ADS_UF_TRUSTED_FOR_DELEGATION =0x80000;
val= (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    ADS_UF_TRUSTED_FOR_DELEGATION;
usr.CommitChanges();

下面的示例说明如何显示该帐户是敏感帐户并且无法用于委托。

[Visual Basic]

Const ADS_UF_NOT_DELEGATED As Integer = &H100000
Val = Fix(usr.Properties("userAccountControl").Value)
usr.Properties("userAccountControl").Value = val Or _
      ADS_UF_NOT_DELEGATED
usr.CommitChanges()
const int ADS_UF_NOT_DELEGATED=0x100000;
val= (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    ADS_UF_NOT_DELEGATED;
usr.CommitChanges();

下面的代码示例说明如何设置该帐户,以使其不要求 Kerberos 预先身份验证。

[Visual Basic]

Const ADS_UF_DONT_REQUIRE_PREAUTH As Integer = &H400000
Val = Fix(usr.Properties("userAccountControl").Value)
usr.Properties("userAccountControl").Value = val Or _
      ADS_UF_DONT_REQUIRE_PREAUTH
usr.CommitChanges()
const int ADS_UF_DONT_REQUIRE_PREAUTH=0x400000;
val= (int) usr.Properties["userAccountControl"].Value;
usr.Properties["userAccountControl"].Value = val | 
    ADS_UF_DONT_REQUIRE_PREAUTH;
usr.CommitChanges();

另请参见

参考

System.DirectoryServices
DirectoryEntry

概念

用户管理

Send comments about this topic to Microsoft.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。