Okay, I gave up I am trying to pull the LastLogon time from Active Directory and I'm having all sorts of issues with the conversion. I know a simple internet search pulls up dozens of examples and I've tried every single one. If anyone could please tell me where I'm going wrong it would be greatly appreciated...
I see, you are using a SearchResultsCollection, here the property value is already converted to a long (from a LARGEINTERGER).
- This gives a date and time at least, unfortunately its not the correct date and time when compared against adsi. I am using the SearchResultsCollection. Is there a better way?
LargeInteger li = Results.Properties["LastLogon"] as LargeInteger;
long expDate = (((long)(li.HighPart) << 32) + (long)li.LowPart);
string dt = DateTime.FromFileTime(expDate).ToString();
- This give a "object reference not set to instance of an object" exception. Taken from many of the search results I also made 2 modifications. The original example had a Results.Properties["LastLogon"].value (.value on the end without the ) which is not valid. Also the last line stated just Date instead of expDate. This seems to be the most popular example but I'm not sure why I cant get it to work.
ActiveDs.IADsLargeInteger li = ((ActiveDs.IADsLargeInteger)(Results.Properties["LastLogon"]));
long date = (long)li.HighPart << 32 | (uint)li.LowPart;
DateTime dt = DateTime.FromFileTime(date);
- This also originally had Results.Properties["LastLogon"].value. Why does it say for me that this is not valid? Using the above gives an exception "unable to case object of type system.int64 to type activeds.iadslargeinteger" There are also a few others that are similar to this all result in this exception.