get last logon time
-
i am not sure how i would do this but i am trying to modify the code below to take a directory entry and check the last logon time on eache domain controler currently it does a directory sear on each domain controler and it becomes unresponsive (this method is being call 1 time for each user on my domain i have over 3,000 users and i already have a DictionaryEntry object created public DateTime LastLogon(string user, string domain) { DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain); DateTime latestLogon = DateTime.MinValue; string servername = null; bool processed = false; DomainControllerCollection dcc = DomainController.FindAll(context); foreach (DomainController dc in dcc) { DirectorySearcher ds; //System.Console.WriteLine(dc.Name); bool exist = false; using (dc) using (ds = dc.GetDirectorySearcher()) { ds.Filter = String.Format("(sAMAccountName={0})", username); ds.PropertiesToLoad.Add("lastLogon"); dc.GetDirectoryEntry ds.SizeLimit = 1; // this search is killing my server SearchResult sr = ds.FindOne(); if (sr != null) { DateTime lastLogon = DateTime.MinValue; if (sr.Properties.Contains("lastLogon")) { exist = true; lastLogon = DateTime.FromFileTime((long)sr.Properties["lastLogon"][0]); } if (DateTime.Compare(lastLogon, latestLogon) > 0) { latestLogon = lastLogon; servername = dc.Name; } } } } return latestLogon; }
-
i am not sure how i would do this but i am trying to modify the code below to take a directory entry and check the last logon time on eache domain controler currently it does a directory sear on each domain controler and it becomes unresponsive (this method is being call 1 time for each user on my domain i have over 3,000 users and i already have a DictionaryEntry object created public DateTime LastLogon(string user, string domain) { DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, domain); DateTime latestLogon = DateTime.MinValue; string servername = null; bool processed = false; DomainControllerCollection dcc = DomainController.FindAll(context); foreach (DomainController dc in dcc) { DirectorySearcher ds; //System.Console.WriteLine(dc.Name); bool exist = false; using (dc) using (ds = dc.GetDirectorySearcher()) { ds.Filter = String.Format("(sAMAccountName={0})", username); ds.PropertiesToLoad.Add("lastLogon"); dc.GetDirectoryEntry ds.SizeLimit = 1; // this search is killing my server SearchResult sr = ds.FindOne(); if (sr != null) { DateTime lastLogon = DateTime.MinValue; if (sr.Properties.Contains("lastLogon")) { exist = true; lastLogon = DateTime.FromFileTime((long)sr.Properties["lastLogon"][0]); } if (DateTime.Compare(lastLogon, latestLogon) > 0) { latestLogon = lastLogon; servername = dc.Name; } } } } return latestLogon; }
I think you might have got the wrong forum - your post certainly has nothing to do with COM - I suspect you may get more assistance posting in the C# forum.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p