Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Im making a batch file im going to put in the all ussers start folder to log what time each user logs on to my laptop. Ive got it so i can log time and date, but is it possible to log what user with a system vatriable(like the %time% and %date% functions)?
Heres my code at the moment:
@echo off
set t=%time%
set d=%date%
echo %d%-%t%>>time.txtGoing to set the date as the file name later after i figure out the user log part.
Thanks if you can help.

RMDan, seems to me you could simply define a variable each time to be the same as the username (which would be different each time) and do the job. Come to think of it, since the username would be different each time you wouldn't need a seperate variable.????????
HTH.
Ed in Texas.

Thats what i want. but i want to find what to put for the username. like is it %user%(thats not it, but same idea) or do i have to do a more complex type script to get it?

Not sure....
This will always place current user at the top of list. It is very simple. If you want seconds change 0,5 to 0,8. Will say cannot find userlog.txt first go but still creates it@echo off
cls
set /p inp=PLEASE TYPE YOUR NAME AND PRESS ENTER: -
set inp=%inp%
@echo logon.....%inp%....%date%.....%time:~0,5%>>"C:\Documents and Settings\########\My Documents\userlog1.txt"
echo. >> "C:\Documents and Settings\########\My Documents\userlog1.txt"
type "C:\Documents and Settings\########\My Documents\userlog.txt" >> "C:\Documents and Settings\########\My Documents\userlog1.txt"
del "C:\Documents and Settings\########\My Documents\userlog.txt"
ren "C:\Documents and Settings\########\My Documents\userlog1.txt" userlog.txt
exit

I dont want it to have to be user imputed though. is it possible for it to check that without anyone needing to enter anything(so i can be accurate each time)

If they have to log on then their log on name should be stored.
If you have XP pro you could try thisecho %username%
@echo off
cls
FOR /F "tokens=3" %%a IN ('netsh diag show computer /v ^| FIND /i "username"') DO ECHO %%a
pause
exitelse you can put the names in a text file and reference that or put their names into the batch file and use that. This involves them obviously inputing name.
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon contains the log on information you can reference that.

"@echo off
set t=%time%
set d=%date%
echo %d%-%t%>>time.txt"There might be some reason for this, but I have no idea what it is.
And we won't even discuss:
set inp=%inp%
YIKES!
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |