Changing User Account Expiry Date to Account Expires Never

  • Thread starter Thread starter Chris Noble
  • Start date Start date
C

Chris Noble

A user account expiration date can be set using the following code

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

Can anyone please tell me what is the recommended way to programmatically
change a user account with an expiry date to Never?
This is equivalent to physically checking the Account Expires Never radio
button in the user properties in the Active Directory Users and Management
Console.

Thanks
 
How about just:
usr.InvokeSet(
"AccountExpirationDate",
new object[] {new DateTime(2099, 12, 29)});

I'm pretty sure most of us won't be around to worry about it then.

Peter
 
Thanks Peter

I'd thought of that but there should be the code behind the mouse click in
the Active Directory Users and Management console but I can't work it out.
I've seen references to Account_Expires property which has dates that start
at Jan 1st 1601 (UTC). A value of 0 indicates the account never expires but
how do/should you access it in C# with Framework 2.0

Chris

Peter Bromberg said:
How about just:
usr.InvokeSet(
"AccountExpirationDate",
new object[] {new DateTime(2099, 12, 29)});

I'm pretty sure most of us won't be around to worry about it then.

Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net




Chris Noble said:
A user account expiration date can be set using the following code

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

Can anyone please tell me what is the recommended way to programmatically
change a user account with an expiry date to Never?
This is equivalent to physically checking the Account Expires Never radio
button in the user properties in the Active Directory Users and
Management
Console.

Thanks
 
Chris Noble said:
A user account expiration date can be set using the following code

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

Can anyone please tell me what is the recommended way to programmatically
change a user account with an expiry date to Never?
This is equivalent to physically checking the Account Expires Never radio
button in the user properties in the Active Directory Users and Management
Console.

Thanks


Set the account to never expire like this:

using (DirectoryEntry user = .....)
{
user.Properties["AccountExpires"].Value = 0;
user.CommitChanges();
}


Willy.
 
Thanks Willy

I'll try this

Willy Denoyette said:
Chris Noble said:
A user account expiration date can be set using the following code

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

Can anyone please tell me what is the recommended way to programmatically
change a user account with an expiry date to Never?
This is equivalent to physically checking the Account Expires Never radio
button in the user properties in the Active Directory Users and
Management Console.

Thanks


Set the account to never expire like this:

using (DirectoryEntry user = .....)
{
user.Properties["AccountExpires"].Value = 0;
user.CommitChanges();
}


Willy.
 
Hi Chris,

Have you tried "Willy Denoyette [MVP]"'s solution? Does it resolve your
problem? If you still need any help or have any concern, please feel free
to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top