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 & “)”
xLdapSearch.PropertiesToLoad.Add(“uSNChanged”)
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
xLdapConnection.Close()
Return xtmpusn
End Function[/vbnet]