设置用户帐户到期

要设置某个帐户的到期日期,请使用 IADsUser.AccountExpirationDate 属性。可以使用两种方式设置此属性。第一种方式使用 InvokeMember 方法。第二种方式使用 InvokeSet 方法,这是 Microsoft .NET Framework 2.0 版中的新方法。有关 IADsUser.AccountExpirationDate 属性的更多信息,请参见位于 https://go.microsoft.com/fwlink/?LinkID=27252 上的 MSDN Library 中的“IADsUser 属性方法”(可能为英文网页)主题。

下面的 C# 示例说明如何使用 InvokeMember 方法设置 IADsUser.AccountExpirationDate 属性的值。

using System.Reflection;

// Get the native object.
Type type = usr.NativeObject.GetType();
Object adsNative = usr.NativeObject;

// Use the Type.InvokeMember method to invoke the 
// AccountExpirationDate property setter.
type.InvokeMember(
    "AccountExpirationDate", 
    BindingFlags.SetProperty, 
    null, 
    adsNative, 
    new object[]{"12/29/2004"});

// Commit the changes.
usr.CommitChanges();

下面的 C# 示例说明如何使用 InvokeSet 方法设置 IADsUser.AccountExpirationDate 属性的值。

// Use the DirectoryEntry.InvokeSet method to invoke the
// AccountExpirationDate property setter.
usr.InvokeSet(
    "AccountExpirationDate", 
    new object[] {new DateTime(2005, 12, 29)});

// Commit the changes.
usr.CommitChanges();

另请参见

参考

System.DirectoryServices
DirectoryEntry

概念

用户管理

Send comments about this topic to Microsoft.

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