共用方式為


設定使用者帳戶到期日

若要設定帳戶到期日,請使用 IADsUser.AccountExpirationDate 屬性。您可以用兩種方式設定此屬性。第一種是使用 InvokeMember 方法。第二種是使用 InvokeSet 方法,這是 Microsoft .NET Framework 2.0 版 的新方法。如需 IADsUser.AccountExpirationDate 屬性的詳細資訊,請參閱 MSDN Library 中的<IADsUser 屬性方法>主題,網址為:https://go.microsoft.com/fwlink/?LinkID=27252 (本頁面可能為英文)。

下列 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.

Copyright © 2007 by Microsoft Corporation.All rights reserved.