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
Solved

vb.net and querying ldap lastLogon

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

808 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