我想将新用户帐户设置为在创建后的90天内过期。这里是我的代码来创建用户并设置一切。除了最后一块我试图将其设置为过期的所有东西都可以工作。使用LDAP和C#设置Active Directory帐户到期时间
DirectoryEntry newUser = dirEntry.Children.Add("CN=" + cnUser, "user");
newUser.Properties["samAccountName"].Value = cnUser;
newUser.Properties["userPrincipalName"].Value = cnUser;
newUser.Properties["pwdLastSet"].Value = 0;
newUser.CommitChanges();
//Changes Password
String passwrd = userPassword.ToString();
newUser.Invoke("SetPassword", new object[] { passwrd });
newUser.CommitChanges();
//Sets User Account to Change Passowrd on new login
newUser.Properties["pwdLastSet"].Value = 0;
newUser.CommitChanges();
//Enables account
newUser.Properties["userAccountControl"].Value = (int)newUser.Properties["userAccountControl"].Value & ~0x2;
newUser.CommitChanges();
//Set the account to expire in 90 days
var dt1 = DateTime.Today.AddDays(90);
newUser.Properties["accountExpires"].Value = dt1.ToFileTime().ToString();
newUser.CommitChanges();
如何让自己的工作有什么建议?
感谢
日期时间的蜱计数从1月蜱0001它需要标准化来算蜱开始1月1日1601 – 2013-03-07 21:47:14
的DateTime.Today.Add(90).Ticks给正确的日期可以达到月份和日期,但是在一年中它已经设置为3613,基本上在滴答开始的地方增加了1600。 – 2013-03-07 21:58:23
好吧,所以减去'新日期时间(1600,1,1).Ticks'应该修复它。更新的答案即将推出 – Gus 2013-03-07 22:12:01