lastLogonTimestamp

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kenneth H. Young

    #1

    lastLogonTimestamp

    I am perplexed. I have a requirement to check for inactive accounts on
    a weekly basis so I am trying to write an application to aid in this.
    I get accurate results for very few user and the rest return the following
    "12/31/1600 7:00:00 PM". I have used the LDAP tool (ldp.exe)
    from the 2003 Resource Kit to check these users and they have valid
    lastLogonTimest amp. I have also tweaked the searchBase to connect
    directly to each of two DC's and I always the erroneous result. If I remark
    out 'On Error Resume Next' I get the following
    "Index was out of range. Must be non-negative and less than the size of the
    collection.
    Parameter name: index" for "Data3 =
    Results.GetDire ctoryEntry().Pr operties("lastL ogonTimestamp") (0)".
    This would indicate that the field doesn't exist but like I stated earlier I
    can look it up for the same user with the ldp tool.

    Any help is greatly appreciated.
    Below is my current code.

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click
    Dim x As Integer
    Dim searchBase As String = "LDAP://dc=ncst,dc=nrl, dc=navy,dc=mil"
    Dim sFilter, Data1, Data2, Data4 As String
    Dim HighV, LowV, llVal As Long
    Dim Data3 As ActiveDs.LargeI nteger
    Me.txtStatus.Te xt = Nothing
    Me.txtResults.T ext = Nothing
    If txtUserName.Tex t = Nothing Or txtUserName.Tex t = "*" Then
    txtUserName.Tex t = "*"
    Data4 = txtUserName.Tex t
    Else
    Data4 = txtUserName.Tex t & "*"
    End If
    Dim Entry As New DirectoryEntry( "" & searchBase & "")
    Entry.Authentic ationType = AuthenticationT ypes.FastBind
    Dim Searcher As New DirectorySearch er(Entry)
    Searcher.PageSi ze = 5000
    sFilter = "(&(objectClass =user)(sAMAccou ntName=" & Data4 & "))"
    Searcher.Filter = sFilter
    Searcher.Proper tiesToLoad.Add( "sn")
    Searcher.Proper tiesToLoad.Add( "sAMAccountName ")
    Searcher.Proper tiesToLoad.Add( "lastLogonTimes tamp")
    On Error Resume Next

    Dim Results As System.Director yServices.Searc hResult
    For Each Results In Searcher.FindAl l()
    HighV = Nothing
    LowV = Nothing
    llVal = Nothing
    Data1 = Nothing
    Data2 = Nothing

    If
    Results.GetDire ctoryEntry().Pr operties("sAMAc countName").Val ue = Nothing
    Then
    Resume Next
    Else
    Data1 =
    Results.GetDire ctoryEntry().Pr operties("sAMAc countName").Val ue
    Data3 =
    Results.GetDire ctoryEntry().Pr operties("lastL ogonTimestamp") (0)
    HighV = Data3.HighPart
    LowV = Data3.LowPart
    llVal = (HighV * 2 ^ 32) - LowV
    Data2 = DateTime.FromFi leTime(llVal)
    Me.txtResults.T ext = Me.txtResults.T ext & Data1 & ": " &
    Data2 & vbCrLf
    x += 1
    End If
    Next
    Me.txtStatus.Te xt = "Search for (" & Data4 & ") Complete..." & x & "
    record(s) found."
    Me.txtUserName. Text = Nothing
    Entry.Close()
    End Sub


Working...