Tuesday , November 24 2020
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 VB.net 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

How to use DNS Pin Point instead Split Horizon – the easy way!

Background on the DNS issue faced There are times when DNS split horizon is required …

Leave a Reply

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