Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. COM
  4. get last logon time

get last logon time

Scheduled Pinned Locked Moved COM
sysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    caiena
    wrote on last edited by
    #1

    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; }

    S 1 Reply Last reply
    0
    • C caiena

      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; }

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups