Solved

vb.net and querying ldap lastLogon

Posted on 2014-10-23
4
365 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 500 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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
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…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

726 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