lastLogonTimestamp

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

    #1

    lastLogonTimestamp

    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


  • Dirk_Drexlin_

    #2
    Re: lastLogonTimest amp

    Kenneth H. Young schrieb:
    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.
    THis means, that the value of lastLogonTimest amp is empty; probably
    because the user never loged on.

    Greetings

    Dirk

    Comment

    • Kenneth H. Young

      #3
      Re: lastLogonTimest amp

      In later testing that's what it seemed like a Null or Nothing returm.
      But I am testing in a single Active Directory server environment against
      known active accounts.


      "Dirk_Drexl in_" <nospamdrexlin@ nospamhgs-calw.dewrote in message
      news:4i432eF1nv ocU1@individual .net...
      Kenneth H. Young schrieb:
      >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.
      >
      THis means, that the value of lastLogonTimest amp is empty; probably
      because the user never loged on.
      >
      Greetings
      >
      Dirk

      Comment

      • Kenneth H. Young

        #4
        Re: lastLogonTimest amp

        OK, I have tested over and over again. I have set the code up to pull
        back all users and then tweaked it to pull from two different servers and
        the results for every user is always the same for lastLogonTimeSt amp
        '12/31/1600 7:00:00 PM'. Any help with this will be greatly appreciated.
        Below is all my code, please excuse the mess.

        Imports System.Director yServices
        Imports System.Windows. Forms
        Imports ActiveDs
        Imports ADODB

        Public Class Form1
        Dim Entry As DirectoryEntry
        Dim Searcher As DirectorySearch er
        Dim rootDSE As IADs
        Dim sObjectDN As String
        Dim timeAdj As Int64
        Dim lngHigh As Int64
        Dim lngLow As Int64

        Private Sub btLastLogon_Cli ck(ByVal sender As System.Object, ByVal e As
        System.EventArg s) Handles btLastLogon.Cli ck
        Dim tDate As DateTime
        Dim valLL As Date
        tDate = Date.Now().AddD ays(-30).ToShortDate String
        Me.TextBox1.Tex t = tDate
        Dim Data1, Data2 As String
        Dim Data3 As ActiveDs.LargeI nteger
        Dim Data4, Data5 As Date
        Dim x As Integer = 0
        Dim llastLogonAdjus t As Long = 127877417297554 938L

        ' 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.UseProper tyCache = False
        Dim Searcher As New DirectorySearch er(Entry)
        Searcher.PageSi ze = 5000
        Dim strContact As String = "(&(objectClass =user)(cn=*))"
        Searcher.Filter = strContact
        Searcher.Proper tiesToLoad.Add( "cn")
        Searcher.Proper tiesToLoad.Add( "lastLogon" )
        Searcher.Proper tiesToLoad.Add( "givenName" )
        Searcher.Proper tiesToLoad.Add( "sn")
        Searcher.Proper tiesToLoad.Add( "lastLogonTimes tamp")
        Dim Results As System.Director yServices.Searc hResult
        On Error Resume Next
        For Each Results In Searcher.FindAl l()
        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
        x += 1
        Skip:

        Next
        Entry.Close()
        'Me.txtStatus.T ext = "Found " & x & " entries."
        End Sub
        End Class


        Comment

        • Dirk_Drexlin_

          #5
          Re: lastLogonTimest amp

          Are you sure, the problem is your program and not the Active Directory?

          What value do you see when you check the properties of a user in the AD?

          Greetings

          Dirk

          Comment

          • Kenneth H. Young

            #6
            Re: lastLogonTimest amp

            I have checked a large number of the users on the server using LDP as well
            as Active Directory Users & Computers 'Additional Account Info' tab and they
            are are populated with a date.



            "Dirk_Drexl in_" <nospamdrexlin@ nospamhgs-calw.dewrote in message
            news:4i63b2F27f c0U1@individual .net...
            Are you sure, the problem is your program and not the Active Directory?
            >
            What value do you see when you check the properties of a user in the AD?
            >
            Greetings
            >
            Dirk

            Comment

            • Travis Sharpe

              #7
              Re: lastLogonTimest amp

              Anytime I retrieve the lastlogon value from AD, I use the following
              calculation, it works fine for me.

              Dim UserDE as new
              DirectoryEntry( "LDAP://cn=sharpe\,trav is,ou=users,dc= cahs,dc=colosta te,dc=edu")

              Dim highpart,lowpar t,lastlogon as long
              highpart = UserDE.Properti es("LastLogonTi meStamp")(0).Hi ghPart
              Lowpart = UserDE.Properti es("LastLogonTi meStamp")(0).Lo wpart
              lastLogon = (HighPart * 2^32) - Lowpart

              msgbox DateTime.FromFi leTime(lastLogo n)


              Kenneth H. Young wrote:
              I have checked a large number of the users on the server using LDP as well
              as Active Directory Users & Computers 'Additional Account Info' tab and they
              are are populated with a date.
              >
              >
              >
              "Dirk_Drexl in_" <nospamdrexlin@ nospamhgs-calw.dewrote in message
              news:4i63b2F27f c0U1@individual .net...
              >Are you sure, the problem is your program and not the Active Directory?
              >>
              >What value do you see when you check the properties of a user in the AD?
              >>
              >Greetings
              >>
              >Dirk
              >
              >

              Comment

              • Kenneth H. Young

                #8
                Re: lastLogonTimest amp

                THANK YOU!

                That works and is the simplest solution I have seen to date.


                "Travis Sharpe" <user@anon.comw rote in message
                news:eWaKdfBrGH A.1648@TK2MSFTN GP02.phx.gbl...
                Anytime I retrieve the lastlogon value from AD, I use the following
                calculation, it works fine for me.
                >
                Dim UserDE as new
                DirectoryEntry( "LDAP://cn=sharpe\,trav is,ou=users,dc= cahs,dc=colosta te,dc=edu")
                >
                Dim highpart,lowpar t,lastlogon as long
                highpart = UserDE.Properti es("LastLogonTi meStamp")(0).Hi ghPart
                Lowpart = UserDE.Properti es("LastLogonTi meStamp")(0).Lo wpart
                lastLogon = (HighPart * 2^32) - Lowpart
                >
                msgbox DateTime.FromFi leTime(lastLogo n)
                >
                >
                Kenneth H. Young wrote:
                >I have checked a large number of the users on the server using LDP as
                >well as Active Directory Users & Computers 'Additional Account Info' tab
                >and they are are populated with a date.
                >>
                >>
                >>
                >"Dirk_Drexlin_ " <nospamdrexlin@ nospamhgs-calw.dewrote in message
                >news:4i63b2F27 fc0U1@individua l.net...
                >>Are you sure, the problem is your program and not the Active Directory?
                >>>
                >>What value do you see when you check the properties of a user in the AD?
                >>>
                >>Greetings
                >>>
                >>Dirk
                >>

                Comment

                Working...