Monday , January 21 2019
Home - Development - Checking LDAP uSNChanged (integer8 value) in VB .net

Checking LDAP uSNChanged (integer8 value) in VB .net

Having problems finding a way to use integer8 values from Active Directory ldap in a Application, I thought i’ll show a simple function written to check the AD uSNChanged. Just call the function with the DN of the object to check.

Must include:
[vb] Imports System.Reflection
[/vb] Function code:
[vbnet]Private Function _ADObjectUsn(ByVal xDN As String)
Dim xLdapConnection As New DirectoryEntry(“LDAP://RootDSE”)
Dim xLdapDomainNC As String = xLdapConnection.Properties(“defaultNamingContext”).Value
xLdapConnection = New DirectoryEntry(“LDAP://” & xLdapDomainNC)
Dim xLdapSearch As New DirectoryServices.DirectorySearcher(xLdapConnection)
xLdapSearch.Filter = “(distinguishedName=” & xDN & “)”
Dim xLdapResult As SearchResult = xLdapSearch.FindOne()
Dim xtmpusn As Long
If Not xLdapResult Is Nothing Then
Dim obj As Object = xLdapResult.GetDirectoryEntry.Properties(“uSNChanged”).Value
‘ __ComObj derives fromObject
‘ Get LowPart property from ILargeInteger (INTEGER8 adstype)
Dim low As Object = obj.[GetType]().InvokeMember(“LowPart”, BindingFlags.GetProperty, Nothing, obj, Nothing)
‘ Get HighPart property from ILargeInteger (INTEGER8 adstype)
Dim high As Object = obj.[GetType]().InvokeMember(“HighPart”, BindingFlags.GetProperty, Nothing, obj, Nothing)
‘ Convert to long
xtmpusn = (Convert.ToInt64(high) << 32) + Convert.ToInt64(low)
End If
Return xtmpusn
End Function[/vbnet]

Check Also

Mac Outlook 2016 Screen/View Crashed and Flashing black

The Outlook 2016 client has been trusted workhorse for email since the full release. ¬†However …

Leave a Reply

Your email address will not be published. Required fields are marked *