PC Review


Reply
Thread Tools Rate Thread

Changing User Account Expiry Date to Account Expires Never

 
 
Chris Noble
Guest
Posts: n/a
 
      19th Jun 2007
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      19th Jun 2007
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" wrote:

> 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
>
>
>

 
Reply With Quote
 
Chris Noble
Guest
Posts: n/a
 
      19th Jun 2007
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 [C# MVP]" <(E-Mail Removed)> wrote in
message news:C1C80BC6-8610-454F-B56D-(E-Mail Removed)...
> 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" wrote:
>
>> 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
>>
>>
>>



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      19th Jun 2007
"Chris Noble" <(E-Mail Removed)> wrote in message
news:Oj%(E-Mail Removed)...
>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.

 
Reply With Quote
 
Chris Noble
Guest
Posts: n/a
 
      19th Jun 2007
Thanks Willy

I'll try this

"Willy Denoyette [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Chris Noble" <(E-Mail Removed)> wrote in message
> news:Oj%(E-Mail Removed)...
>>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.
>



 
Reply With Quote
 
Jeffrey Tan[MSFT]
Guest
Posts: n/a
 
      22nd Jun 2007
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/subscripti...ult.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/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
list the date that a user account expires =?Utf-8?B?TWFyY2Vsbw==?= Windows XP Configuration 1 19th Oct 2006 04:07 AM
changing outlook 2003 from pop3 account to exchange server account =?Utf-8?B?VFQ=?= Microsoft Outlook Discussion 1 11th Aug 2006 10:29 PM
Copying user profile from one user account to another user account on the same conputer ---- 3 challenges , 2 of them solved bobdouble@hotmail.com Windows XP Setup 2 4th Mar 2006 08:24 AM
Windows 2000 account expiry date hasanmxs@hotmail.com Microsoft Windows 2000 Active Directory 1 22nd Oct 2003 02:01 PM
Assign "Account Expires" date to multiple user accounts Michael O'Brien Microsoft Windows 2000 Active Directory 1 3rd Sep 2003 07:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:53 AM.