1

I'm trying to get the LastLogon from a user in the active directory but I have this code

 lblUsernameDisplay.Text = "LastLogon : " + (DateTime.FromFileTime((long)rs.GetDirectoryEntry().Properties["lastLogon"][0])).ToString();

And I got an error, I also tried without long cast, without ToString() and with .Value.ToString() instead of [0]

UPDATE:

I got this error: Specified cast is not valid.

  • What is the error you get? – Mark C. Jun 15 '16 at 19:49
  • @MarkC. Long cast isn't allowed here, and if I do like this --´rs.GetDirectoryEntry().Properties["lastLogon"][0].ToString(); returns me a´System.___Com.... – Horacio Garza Jun 15 '16 at 19:52
  • You sure this SO question wouldn't help? It covers this question and how to handle with multiple domain controllers. http://stackoverflow.com/questions/19454162/getting-last-logon-time-on-computers-in-active-directory – John Jun 15 '16 at 20:12

0 Answers0