Note that there are some explanatory texts on larger screens.

plurals
  1. POCasting ActiveDirectory pwdLastSet property without using ActiveDs
    primarykey
    data
    text
    <p>Ok. So I'm trying to find a way to avoid including ActiveDs in my project because I'm having trouble getting the dll to show up in the installer. The only reason to have it is to cast the pwdLastSet as a LongInteger.</p> <p>I found an undocumented alternative. When testing it, it is either dead on or 429.49673 seconds off. I'm not sure why, does anybody have any idea? (20/49 people that i tested are 429.49673 seconds off).</p> <p><strong>UPDATE</strong>: It looks like it happens when the LowPart is negative.</p> <p>Code:</p> <pre><code> private static string DateTest() { return DateTest(Environment.UserName); } private static string DateTest(string userName) { userName = userName.Trim(); DateTime hacked, normal; using (DirectorySearcher ds = new DirectorySearcher()) { ds.SearchScope = SearchScope.Subtree; ds.PropertiesToLoad.Add("distinguishedName"); ds.PropertiesToLoad.Add("pwdLastSet"); ds.PageSize = 1; ds.ServerPageTimeLimit = TimeSpan.FromSeconds(2); ds.Filter = string.Format("(&amp;(objectCategory=user)(sAMAccountName={0}))", userName); SearchResult sr = ds.FindOne(); hacked = DateTime.FromFileTime((long)sr.Properties["pwdLastSet"][0]); using (DirectoryEntry user = sr.GetDirectoryEntry()) { var value = user.Properties["pwdLastSet"][0] as ActiveDs.LargeInteger; var longValue = (((long)value.HighPart) &lt;&lt; 32) + (long)value.LowPart; normal = DateTime.FromFileTime(longValue); } } return string.Format("{3} - Difference: {0:0.0} seconds. Established Method returns: {1}. Hacked method returns: {2}", hacked.Subtract(normal).TotalSeconds, normal, hacked, userName); } } </code></pre> <p>References: </p> <ul> <li>Active DS Type Library</li> <li>System.DirectoryServices</li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload