Active Directory上次密码更改日期和时间

时间:2016-05-20 17:50:05

标签: c# asp.net visual-studio active-directory

我在C#中编写代码以查找Active Directory中的上次密码更改日期和时间。我已经能够找到日期看到一些例子,但没有找到正确的时间戳。有人可以帮忙吗?到目前为止我的代码是:

DirectoryEntry de = (DirectoryEntry)foundUser.GetUnderlyingObject();
if (de.Properties["pwdLastSet"].Value != null)
{
     LargeInteger liAcctPwdChange = de.Properties["pwdLastSet"].Value as LargeInteger;
     long dateAcctPwdChange = (((long)(liAcctPwdChange.HighPart) << 32) + (long)liAcctPwdChange.LowPart);
     Label1.Text = DateTime.FromFileTime(dateAcctPwdChange).ToShortDateString();
}

1 个答案:

答案 0 :(得分:0)

尝试更改

long dateAcctPwdChange = (((long)(liAcctPwdChange.HighPart) << 32) + (long)liAcctPwdChange.LowPart);
Label1.Text = DateTime.FromFileTime(dateAcctPwdChange).ToShortDateString();

到此

long dateAcctPwdChange = (((long)(liAcctPwdChange.HighPart) << 32) + (uint)liAcctPwdChange.LowPart);
Label1.Text = DateTime.FromFileTimeUtc(dateAcctPwdChange).ToString();

将上一个long更改为uint,将FromFileTime更改为FromFileTimeUtc

有关MSDN的快速参考示例:https://msdn.microsoft.com/en-us/library/ms180872(v=vs.90).aspx