Last Logon date to XP or NT

I have been tasked with creating a report that shows which machines have not been used in the last month. I suspect the only way to do that is to find some way of showing when a machine was last logged on to.

I am using landesk to collect the information. I can look at when a file was last executed or find a registry key.

I have tried using userinit.exe but the results were not reliable. Does anyone know of a way to show this?


Who is Participating?
The 'Event Viewer' security log should show when a user logged on/off, and the application log will show which user executed an application and when. You'll need to read the files rather than just look at the timestamp I'm afraid.

If the logon is authenticated as part of an domain, then the server logs may be of use?

(   (()
(`-' _\
 ''  ''
PLSMAuthor Commented:
Ah... Unfortunately we do not have Auditing enabled on any of our client computers, and this has got to work retrospectively.

I will have a look at AD, but I seem to remember that AD can only give you last login for the users, not when a computer was last logged in to. However, I could well be wrong!

Excellent.....This should not be to bad.  The first thing that comes to mind is to just take a look at the "C:\documents and settings" folder using the "Details" view.  Check the modified dates and this will show you the last time the computer was logged into, and by whom.

If your workstation base is larger like mine.  Just write a script to do it.  You could get export a list or workstations out of AD or even Server Manager (NT) and then just loop your script to collect file modify dates from each machine.  Easy pleasy.

If your not a scripter, check out:

Its a great resource...
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

In an XP machine, look in the "Documents and settings folder". You can check the date stamp on the hidden file NTUSER.DAT.   The date should give you a good idea when the mahcine was last used by that person.  

You'll need to look in every profile directory for each instance of NTUSER.DAT, and return the most recent date on the ntuser file from any of the profile directories.  

PberSolutions ArchitectCommented:
Try this script:


dtmDate = DateAdd("d", -MAXIMUM_PASSWORD_AGE, Now())
dbl100NanoSecs = 10000000 * (DateDiff("s", "1/1/1601", dtmDate))
dbl100NanoSecs = FormatNumber(dbl100NanoSecs, 0, False, False ,0)

set oRootDSE = GetObject("LDAP://RootDSE")
strDomainNC = oRootDSE.Get("defaultNamingContext")
set oRootDSE = Nothing

Set oConnection   = CreateObject("ADODB.Connection")
oConnection.Provider   = "ADsDSOObject"
oConnection.Open "Active Directory Provider"

Set oCommand = CreateObject("ADODB.Command")
Set oCommand.ActiveConnection = oConnection

strQuery = "<LDAP://" & strDomainNC & ">;(&(objectCategory=Computer)(lastLogonTimestamp<=" & dbl100NanoSecs & "));ADSPath;subtree"  
WScript.Echo strQuery
oCommand.CommandText = strQuery  
oCommand.Properties("Page Size") = 1000
Set oRecordSet = oCommand.Execute

if not oRecordSet.Eof Then

      WScript.Echo "Total: " & oRecordSet.RecordCount
      While Not oRecordSet.Eof
            Set ObjComp = GetObject(oRecordSet.Fields("AdsPath").Value)
            set objLogon = ObjComp.Get("lastLogonTimestamp")
            intLogonTime = objLogon.HighPart * (2^32) + objLogon.LowPart
            intLogonTime = intLogonTime / (60 * 10000000)
            intLogonTime = intLogonTime / 1440
            intLogonTime = intLogonTime + #1/1/1601#
            WScript.Echo Replace(,"CN=","") & ", " & intLogonTime
      '      End if
end If
PberSolutions ArchitectCommented:
Hmmmm, now that I read your post, this will probably not do the trick.  This will show the last time the computer was last on the domain, but for it to work in your case, the machine would have had to been powered off or disconnected from the network.
Probably what you want is a software like this, LANsurveyor >
This program can be modified to retrieve the lastLogon date for all
computers instead of all users by changing this statement:

strFilter = "(& (objectCategory=person)(objectClass=user
to this:
strFilter = "(objectCategory=computer)"

I hope this helps.

PLSMAuthor Commented:
Thanks for all the comments. I will try it all and come back to the group.
Administrative Tools
- Domain Security Polices > Local Polices > Audit Policies
- Define Audit Account Logon Events
- Define Audit Logon Events
event viewer, rclk System Log > Properties > Filter (by computer, user, etc)

also see this from robwill
plsm, plx respond to the advice in my last comment on 7/2
PLSMAuthor Commented:
The resolution has been found. Thanks for all your comments. Unfortunately LANDesk has to be used for this task for political reasons.

In case your are interested, in brief, we have solved this by writing a login/logoff date, time, and user name to the client machines, using some VBS in a login script. Using the login script we do some time calculation to find the difference between login and logout. That value is then written to another key, named by month. Every time someone logs on and off the time value found is added to the value already in the month key. When a new month starts a new month key is created. That key can then be found by LANDesk and reports can be made.

Thanks again for you comments.
so you didn't find the script from Robwill from the below link (orginally listed in above thread) helpful to build your script?
PLSM, can you please follow my advice above? It helps a lot if you close your own question, thanks.

EE Cleanup Volunteer
PLSM, are you still there? Have you read my last post?
i think my comment from 7/2 should be accepted since he stated on 7/24 he made a login/logoff script which my link pointing to Robwill's advice more than likely helped them make theirs or at least mentions doing so which led to the answer.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.