username in batch code

gateway
October 20, 2008 at 22:21:05
Specs: xp, ?
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.txt

Going to set the date as the file name later after i figure out the user log part.

Thanks if you can help.


See More: username in batch code

Report •


#1
October 20, 2008 at 22:48:20
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.

Report •

#2
October 20, 2008 at 23:04:30
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?

Report •

#3
October 21, 2008 at 00:33:12
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


Report •

Related Solutions

#4
October 21, 2008 at 15:11:12
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)

Report •

#5
October 21, 2008 at 23:03:41
If they have to log on then their log on name should be stored.
If you have XP pro you could try this

echo %username%

@echo off
cls
FOR /F "tokens=3" %%a IN ('netsh diag show computer /v ^| FIND /i "username"') DO ECHO %%a
pause
exit

else 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.


Report •

#6
October 22, 2008 at 12:59:57
"@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


Report •


Ask Question