Link to home
Start Free TrialLog in
Avatar of centem
centemFlag for United States of America

asked on

Account Expiration with System.DirectoryServices.AccountManagement

Hi, I'm creating an acount using the System.DirecotryServices.AccountMangement. All works except for the expiration date on the accounts does not reflect what typed into the textbox. Below is the code. How can I get the account expiration date onto the account. Thanks.

PrincipalContext AddContext = new PrincipalContet(ContextType.Domain, "domain.com", context);
        UserPrincipal usr = new UserPrincipal(AddContext, newuser, "password", true);
        usr.GivenName = fn;
        usr.MiddleName = mi;
        usr.Surname = ln;
        usr.SamAccountName = newuser;
        usr.UserPrincipalName = newuser + "@domain.com";
        usr.AccountExpirationDate = Convert.ToDateTime(txtVarDate.Text);
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Be aware that the datetime stored on the account will be in UTC form. What you are doing in the above code looks fine.

http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.authenticableprincipal.accountexpirationdate(v=VS.90).aspx
Avatar of centem

ASKER

Thank you very much. Although its behind by two days. For example, when I set it to 2012-05-05 I actually get 2012-05-03. How can I fix that? Thanks.
This article should help to explain the discrepancy : http://www.rlmueller.net/AccountExpires.htm