Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

4 Answers 4

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

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

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
1  
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 Answer

 
discard

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.