Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is some code I found: </p> <pre><code>using System; // has DateTime class using System.Collections.Generic; // has the Dictionary class using System.DirectoryServices; // has all the LDAP classes such as DirectoryEntry using ActiveDs; // has the IADsLargeInteger class // Get the root entry DirectoryEntry rootDSE = new DirectoryEntry("LDAP://RootDSE"); string configurationNamingContext = (string)rootDSE.Properties["configurationNamingContext"].Value; string defaultNamingContext = (string)rootDSE.Properties["defaultNamingContext"].Value; // Get all the domain controllers // Get all the domain controllers DirectoryEntry deConfig = new DirectoryEntry("LDAP://" + configurationNamingContext); DirectorySearcher dsConfig = new DirectorySearcher(deConfig); dsConfig.Filter = "(objectClass=nTDSDSA)"; foreach (SearchResult srDomains in dsConfig.FindAll()) { DirectoryEntry deDomain = srDomains.GetDirectoryEntry(); if (deDomain != null) { string dnsHostName = deDomain.Parent.Properties["DNSHostName"].Value.ToString(); // Get all the users for that domain } } // Get all the users for that domain DirectoryEntry deUsers = new DirectoryEntry("LDAP://" + dnsHostName + "/" + defaultNamingContext); DirectorySearcher dsUsers = new DirectorySearcher(deUsers); dsUsers.Filter = "(&amp;(objectCategory=person)(objectClass=user))"; foreach (SearchResult srUsers in dsUsers.FindAll()) { DirectoryEntry deUser = srUsers.GetDirectoryEntry(); if (deUser != null) { // Get the distinguishedName and lastLogon for each user // Save the most recent logon for each user in a Dictionary object } } //Create Dictionary Dictionary&lt;string, Int64&gt; lastLogons = new Dictionary&lt;string, Int64&gt;(); // Get the distinguishedName and lastLogon for each user string distinguishedName = deUser.Properties["distinguishedName"].Value.ToString(); Int64 lastLogonThisServer = new Int64(); if (deUser.Properties["lastLogon"].Value != null) { IADsLargeInteger lgInt = (IADsLargeInteger)deUser.Properties["lastLogon"].Value; lastLogonThisServer = ((long)lgInt.HighPart &lt;&lt; 32) + lgInt.LowPart; } // Save the most recent logon for each user in a Dictionary object if (lastLogons.ContainsKey(distinguishedName)) { if (lastLogons[distinguishedName] &lt; lastLogonThisServer) { lastLogons[distinguishedName] = lastLogonThisServer; } } else { lastLogons.Add(distinguishedName, lastLogonThisServer); } //Get the time // Convert the long integer to a DateTime value string readableLastLogon = DateTime.FromFileTime(lastLogonThisServer).ToString(); </code></pre> <p>Here is the website where all of this code came from. The developer explained the code in detail. <a href="http://www.codeproject.com/Articles/19181/Find-LastLogon-Across-All-Windows-Domain-Controlle" rel="nofollow">http://www.codeproject.com/Articles/19181/Find-LastLogon-Across-All-Windows-Domain-Controlle</a></p>
    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.
    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