?
Solved

vb.net and querying ldap lastLogon

Posted on 2014-10-23
4
Medium Priority
?
379 Views
Last Modified: 2014-10-24
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.

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

Open in new window


Can someone tell me how to take the below and make it equal a textbox:
dim pwd as object = entry.Properties("lastLogon").Value

Like
pwd = textbox1.text???
0
Comment
Question by:derek7467
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 71

Expert Comment

by:Chris Dent
ID: 40401727
Surely you just need:
textbox1.text = pwd.ToString()

Open in new window

pwd here is DateTime so any of the extended string formatting options should work for you as well.

Chris
0
 

Author Comment

by:derek7467
ID: 40401978
didnt work, still get the sys_comobject in the textbox
0
 
LVL 71

Accepted Solution

by:
Chris Dent earned 2000 total points
ID: 40402019
My apologies, pwdDate is the one you'd converted to DateTime.
textbox1.text = pwdDate.ToString()

Open in new window

Chris
0
 

Author Closing Comment

by:derek7467
ID: 40402053
Sorry i shoulda realized that.  It worked!  You ROCK!
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Microsoft Office 365 is a subscriptions based service which includes services like Exchange Online and Skype for business Online. These services integrate with Microsoft's online version of Active Directory called Azure Active Directory.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question