次の方法で共有


Setting a User Account Expiration

To set the date on which an account expires, use the IADsUser.AccountExpirationDate property. This property can be set in two ways. The first is to use the InvokeMember method. The second is to use the InvokeSet method, which is new with Microsoft .NET Framework version 2.0. For more information about the IADsUser.AccountExpirationDate property, see the IADsUser Property Methods topic in the MSDN Library at https://go.microsoft.com/fwlink/?LinkID=27252.

The following C# example shows how to use the InvokeMember method to set the value of the IADsUser.AccountExpirationDate property.

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

The following C# example shows how to use the InvokeSet method to set the value of the IADsUser.AccountExpirationDate property.

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

See Also

Reference

System.DirectoryServices
DirectoryEntry

Concepts

User Management

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation. All rights reserved.