PDA

View Full Version : AD lastLogonTimestamp Is my code right?



itipu
10-02-2007, 03:27 AM
Here is what I am using:

adoLastLogon = objRecordSet.Fields("lastLogonTimestamp")
On Error Resume Next
Err.Clear
Set longDate = adoLastLogon
If Err.Number <> 0 Then
Err.Clear
logonDate = "No Local Logon"
Else
longDateHigh = longDate.HighPart
longDateLow = longDate.LowPart
If (longDateLow = 0) And (longDateHigh = 0) Then
logonDate = "No Local Logon"
Else
If longDateLow < 0 Then longDateHigh = longDateHigh + 1
logonDate = #1/1/1601# + (((longDateHigh * (2 ^ 32)) + longDateLow) / 600000000 / 1440)
End If
End If

On a couple of occasions however I've noticed that my "No Local Logon" is lying appearing when machine is actually active.. Have I missed something?

Thanks a lot

Mike

rory
10-02-2007, 05:49 AM
I can't see a problem with the code, so I would suspect the data you are getting is giving you zeroes or triggering an error. Where are you getting the data from - if it's a domain controller, how many do you have? It may be that the logon data is not being propagated to the server you are extracting it from.