Take the tour ×

My idea is to make log-in and log-out scripts to capture the login/logout time and save it to a file (or into a Database). But, i have no idea how to capture the time.

share|improve this question
I found this script to capture the local machine last logon. –  Luigi Siri May 14 '12 at 18:00
add comment

3 Answers

up vote 3 down vote accepted

The easiest thing to do - that I would do to collect the most potentially relevant information - is to create batch scripts with the following lines (and place the batch scripts in Group Policy logon and logoff scripts - with .cmd extensions)

for logon:

echo %username% logged on from %computername% on %date% at %time%>>\server\share\logon.log

and for logout:

echo %username% logged off from %computername% on %date% at %time%>>\server\share\logoff.log

(You can use the same file and don't need to separate them, but for convenience, I split them into two files).

The above should append a line to the files logon.log or logoff.log (as appropriate) with the user's account name, the computer that the user logged in from, and the date and time.

By opening the file in excel and using the text-to-columns feature, you can easily create sortable reports. (And you can leave off the text simplifying the logged data into something like echo %username%,%computername%,%date%,%time%)

share|improve this answer
Yeah buddy! that's the answer. Thanks –  Luigi Siri May 15 '12 at 13:38
add comment

If you're using BAT, then just use time /t. Easy as cake.

share|improve this answer
add comment

If you are planning to do this with scripts you can easily assign a VBS script to be run on logon in either Active Directory or Group Policy and just write login time, server name and user to a SQL Database.

share|improve this answer
Thanks. But, Which other way can i use for that goal? (without the scripts) –  Luigi Siri May 14 '12 at 17:54
Luigi, in your question you clearly state that you want to achieve this via scripts. –  joeqwerty May 14 '12 at 18:17
Yes, and i continue with the idea. But if there is a more efficient way to do it, I'll do it. –  Luigi Siri May 14 '12 at 19:03
add comment

Your Answer


