473,396 Members | 2,115 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Changing User Account Expiry Date to Account Expires Never

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
Jun 19 '07 #1
5 18590
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
Jun 19 '07 #2
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]" <pb*******@yahoo.yabbadabbadoo.comwrote in
message news:C1**********************************@microsof t.com...
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

Jun 19 '07 #3
"Chris Noble" <ch*********@newsgroup.nospamwrote in message
news:Oj****************@TK2MSFTNGP03.phx.gbl...
>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.

Jun 19 '07 #4
Thanks Willy

I'll try this

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:us**************@TK2MSFTNGP02.phx.gbl...
"Chris Noble" <ch*********@newsgroup.nospamwrote in message
news:Oj****************@TK2MSFTNGP03.phx.gbl...
>>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.

Jun 19 '07 #5
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.

Jun 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
1
by: | last post by:
How does one read and write the cookie expiration date. At the moment my code is returning a value BUT a garbled value: '//Write cookie... Response.Cookies("Propsect").Expires = Date() + 1 ...
6
by: Ray | last post by:
Below is the code to save the cookie and set the expiry date of the cooki Response.Cookies.Value ="Hello" DateTime dt = DateTime.Now TimeSpan ts = new TimeSpan(0,0,10,0) Response.Cookies...
4
by: William Bradley | last post by:
I have two cells on a form. One of them is the "Production Date" and the other is the "Expiry Date". The "Expiry Date" is 183 days after the "Production Date." On an Excel spreadsheet, the...
2
by: William Bradley | last post by:
"Marshall Barton" <marshbarton@wowway.com> wrote in message news:9as9lvgpnp783kogctb88c8giaepb5uf6g@4ax.com... > William Bradley wrote: > >I have two cells on a form. One of them is the...
3
by: hasanainf | last post by:
Hi all, What will be the best database design for an inventory control that uses expiry date for its products. Over a period of time, a particular product will have many expiry date and that...
1
by: Rob Kell | last post by:
I have a vb.net application that emails people daily information. I want to set an expiry for the email so that those who cannot check their emails for a period are not loaded with them when they...
12
by: shane.taylor81 | last post by:
Consider the following table Customer custId char(10) accountExpiryDate datetime accountStatus bit Now, I want to update the accountStatus to False as soon as the current date becomes...
1
by: tutusaint | last post by:
I have a user login authentication scrip which validates users emailid and password. I want it to also check and validate users expiry date in the database. I have user details like name,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.