PC Review


Reply
Thread Tools Rate Thread

System.Byte[] And System.__ComObject in Active Directory LDAP brow

 
 
=?Utf-8?B?RGFycmVuIChVSyk=?=
Guest
Posts: n/a
 
      1st Nov 2007
Hello,

I have a small issue with some of the information returned in an LDAP
browser. On certain attributes it returns either System.Byte[] And
System.__ComObject

I suspect this is a result of the data held. For example i know that
PwdLastSet attrib attrib is stored as Int64 values. How do i determine what
System.Byte[] And System.__ComObject are??

A little research has yielded the following:

If you use the DirectorySearcher, it marshals AD INTEGER8 types to .NET
Int64 automatically, so no work needs to be done. This is by far the easiest
way.

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("pwdLastSet").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.InterfaceI sDual)> _
public interface IADsLargeInteger
property HighPart as int32
property LowPart as int32
end interface

Note that you can also get the high and low values via reflection and late
binding or by importing the activeds.dll COM object into .NET.

Qn: I am new to Vb.net and still learning. How can i incorporate the above
to return what i need????

MANY MANY THANKS


------------------------------------------------------------- MY CODE
---------------------------------------------------------------------

Imports System
Imports System.DirectoryServices
Imports System.DirectoryServices.ActiveDirectory
Imports System.Windows.Forms


Public Class LDAPBrowser

Private Base As DirectoryEntry
Private str As String()

Private Sub LDAPBrowser_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Connect()

End Sub

Private Sub tvwADStructure_AfterSelect(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles
tvwADStructure.AfterSelect

'Fill the TreeView dynamic after Click
If e.Node.Nodes.Count = 0 Then

Dim parent As DirectoryEntry = DirectCast(e.Node.Tag,
DirectoryEntry)

If parent IsNot Nothing Then

If parent.Children IsNot Nothing Then

For Each Iter As DirectoryEntry In parent.Children

Dim childNode As TreeNode =
e.Node.Nodes.Add(Iter.Name)

childNode.Tag = Iter

Next
End If
End If
End If

'Fill the ListView Element
Try

Dim list As DirectoryEntry = DirectCast(e.Node.Tag,
DirectoryEntry)

If list IsNot Nothing Then

lstAttribs.Clear()

'Add some information to ListView ELement
lstAttribs.Columns.Add("Attribute", 90,
HorizontalAlignment.Left)
lstAttribs.Columns.Add("Value", 350, HorizontalAlignment.Left)


For Each listIter As Object In list.Properties.PropertyNames

For Each Iter As Object In
list.Properties(listIter.ToString())
Dim item As New
System.Windows.Forms.ListViewItem(listIter.ToString(), 0)

item.SubItems.Add(Iter.ToString())

lstAttribs.Items.AddRange(New ListViewItem() {item})

Next
Next
End If

Catch ex As System.Exception

MessageBox.Show(ex.Message)

End Try

End Sub

Private Sub Connect()

'Pass Connect info to DirectoryEntry object:

Base = New DirectoryEntry("LDAP://XX.XXXXX.com")

'Read the root:
If Base IsNot Nothing Then

tvwADStructure.Nodes.Clear()
tvwADStructure.BeginUpdate()

Dim childNode As TreeNode = tvwADStructure.Nodes.Add(Base.Name)
childNode.Tag = Base

Try
For Each rootIter As DirectoryEntry In Base.Children

Dim RootNode As TreeNode =
childNode.Nodes.Add(rootIter.Name)

RootNode.Tag = rootIter
Next
Finally

childNode.Expand()

tvwADStructure.EndUpdate()

End Try
End If

End Sub

End Class

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Active Directory] On what ground does LDAP connect to Active Directory RTT Microsoft VB .NET 0 12th Apr 2005 04:20 PM
Issues: How to turn off the mpg video clips playing in the IE brow =?Utf-8?B?Z3pxMQ==?= Windows XP Internet Explorer 1 3rd Aug 2004 07:16 PM
Moving From Novell LDAP (NLDAP) To Active Directory LDAP =?Utf-8?B?U3RlcGhlbiBNb29yZQ==?= Microsoft Windows 2000 Active Directory 1 27th Apr 2004 12:44 AM
Active Directory & LDAP Directory =?Utf-8?B?QmVybmll?= Microsoft Outlook 1 17th Feb 2004 11:44 AM
windows 2003 IE 6.0 closes when I click on the link, but I can surf in same brow Money Windows XP Internet Explorer 1 21st Jan 2004 12:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 PM.