Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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). 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
up vote 4 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

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

share|improve this answer

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

your script is wrong

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

this one right script

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

your script is wrong

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

this one right script

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.