I am trying to write a VB app in VS.net to find the lastLogonTimest amp and
have found some example but the answer returned is always the same
'12/31/1600 7:00:00 PM' for any user account.
Thanks!
Below is a snippet of the code.
Dim Data1 As String
Dim Data3 As ActiveDs.LargeI ntergerClass
Dim Data4 as Date
Din lngHigh, lngLow, timeAdj As Int64
Dim x As Integer = 0
' Bind to the Default Active Directory with the RootDSE object.
rootDSE = GetObject("LDAP ://RootDSE")
sObjectDN = "LDAP://" & rootDSE.Get("de faultNamingCont ext")
Me.txtStatus.Te xt = "Connecting to: " & sObjectDN
Dim EntryPath As String = ("" & sObjectDN & "")
Entry = New DirectoryEntry( EntryPath)
Entry.RefreshCa che()
Dim Searcher As New DirectorySearch er(Entry)
Searcher.PageSi ze = 5000
Dim strContact As String = "(&(objectClass =user)(mail=sue *))"
Searcher.Filter = strContact
Searcher.Proper tiesToLoad.Add( "cn")
Searcher.Proper tiesToLoad.Add( "lastLogon" )
Searcher.Proper tiesToLoad.Add( "givenName" )
Searcher.Proper tiesToLoad.Add( "sn")
Dim Results As System.Director yServices.Searc hResult
On Error Resume Next
For Each Results In Searcher.FindAl l()
Data1 = Nothing
Data3 = Nothing
If Not Results.GetDire ctoryEntry().Pr operties("cn"). Value =
Nothing Then
Data1 =
Results.GetDire ctoryEntry().Pr operties("cn"). Value.ToString
Else : GoTo Skip
End If
Data3 =
Results.GetDire ctoryEntry().Pr operties("lastL ogonTimestamp") .Value
lngHigh = Data3.HighPart
lngLow = Data3.LowPart
timeAdj = lngHigh * (2 << 32) + lngLow
timeAdj = timeAdj / (60 * 10000000)
timeAdj = timeAdj / 1440
Data4 = DateTime.FromFi leTime(timeAdj) .ToShortDateStr ing & " " &
DateTime.FromFi leTime(timeAdj) .ToShortTimeStr ing
Data4 = Data4 + #1/1/1601#
Me.txtResults.T ext = Me.txtResults.T ext & Data1 & ", " & Data4 &
vbCrLf
Skip:
Next
have found some example but the answer returned is always the same
'12/31/1600 7:00:00 PM' for any user account.
Thanks!
Below is a snippet of the code.
Dim Data1 As String
Dim Data3 As ActiveDs.LargeI ntergerClass
Dim Data4 as Date
Din lngHigh, lngLow, timeAdj As Int64
Dim x As Integer = 0
' Bind to the Default Active Directory with the RootDSE object.
rootDSE = GetObject("LDAP ://RootDSE")
sObjectDN = "LDAP://" & rootDSE.Get("de faultNamingCont ext")
Me.txtStatus.Te xt = "Connecting to: " & sObjectDN
Dim EntryPath As String = ("" & sObjectDN & "")
Entry = New DirectoryEntry( EntryPath)
Entry.RefreshCa che()
Dim Searcher As New DirectorySearch er(Entry)
Searcher.PageSi ze = 5000
Dim strContact As String = "(&(objectClass =user)(mail=sue *))"
Searcher.Filter = strContact
Searcher.Proper tiesToLoad.Add( "cn")
Searcher.Proper tiesToLoad.Add( "lastLogon" )
Searcher.Proper tiesToLoad.Add( "givenName" )
Searcher.Proper tiesToLoad.Add( "sn")
Dim Results As System.Director yServices.Searc hResult
On Error Resume Next
For Each Results In Searcher.FindAl l()
Data1 = Nothing
Data3 = Nothing
If Not Results.GetDire ctoryEntry().Pr operties("cn"). Value =
Nothing Then
Data1 =
Results.GetDire ctoryEntry().Pr operties("cn"). Value.ToString
Else : GoTo Skip
End If
Data3 =
Results.GetDire ctoryEntry().Pr operties("lastL ogonTimestamp") .Value
lngHigh = Data3.HighPart
lngLow = Data3.LowPart
timeAdj = lngHigh * (2 << 32) + lngLow
timeAdj = timeAdj / (60 * 10000000)
timeAdj = timeAdj / 1440
Data4 = DateTime.FromFi leTime(timeAdj) .ToShortDateStr ing & " " &
DateTime.FromFi leTime(timeAdj) .ToShortTimeStr ing
Data4 = Data4 + #1/1/1601#
Me.txtResults.T ext = Me.txtResults.T ext & Data1 & ", " & Data4 &
vbCrLf
Skip:
Next
Comment