derek7467
asked on
vb.net and querying ldap lastLogon
I am attempting to pull back lastLogon from LDAP, which returns system.com object or some junk like that. I am using the below code to attempt to translate that code into date/time format, but im kinda of confused.
Can someone tell me how to take the below and make it equal a textbox:
dim pwd as object = entry.Properties("lastLogo n").Value
Like
pwd = textbox1.text???
If you use the DirectoryEntry, it marshals the value as an ADSI
IADsLargeInteger type, which at runtime is a System.__ComObject. This is
annoying, but you can get the value with a little interop and some data
munging. This works for me:
dim entry as new DirectoryEntry("LDAP://yourdn here")
dim pwd as object = entry.Properties("lastLogon").Value
dim pwdDate as DateTime
pwdDate = DateTime.FromFileTimeUtc(GetInt64FromLargeInteger(pwd))
Function GetInt64FromLargeInteger(byval largeInteger as Object) as Int64
dim low as int32
dim high as int32
dim valBytes(7) as byte
dim longInt as IADsLargeInteger = Ctype(largeInteger, IADsLargeInteger)
low = longInt.LowPart
high = longInt.HighPart
BitConverter.GetBytes(low).CopyTo(valBytes, 0)
BitConverter.GetBytes(high).CopyTo(valBytes, 4)
Return BitConverter.ToInt64(valBytes, 0)
End Function
<ComImport(), Guid("9068270b-0939-11D1-8be1-00c04fd8d503"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface
Can someone tell me how to take the below and make it equal a textbox:
dim pwd as object = entry.Properties("lastLogo
Like
pwd = textbox1.text???
ASKER
didnt work, still get the sys_comobject in the textbox
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry i shoulda realized that. It worked! You ROCK!
Open in new window
pwd here is DateTime so any of the extended string formatting options should work for you as well.Chris