Solved

vb.net and querying ldap lastLogon

Posted on 2014-10-23
4
323 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
  • 2
  • 2
4 Comments
 
LVL 70

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 70

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

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now