Saturday, February 28, 2009

IN WHICH USER YOU LOG IN TO THE SYSTEM

XP batch files: Create variable for current user account
and find current user this recipe is just a quick batch
file that lets you find the user who is currently logged
in when the batch file is ran by using a FOR statement
and the %USERPROFILE% variable in XP.
This batch file will do the following:
Find the current user logged in when the file is ran
setup a variable, user, whose value will be set to the
user logged in and then echo back the user log in.
Save the code written below in a notepad and save it
as extension any name.bat (any name is the name u like).


@echo off
for /f "tokens=3 delims=\" %%i in ("%USERPROFILE%") do (set user=%%i) 2>&1
echo "logged in user:%user%"
pause
this can be very useful when used in conjunction with other batch file commands.
if you want this info be put into a text file just use this command
Quote:
@echo off
for /f "tokens=3 delims=\" %%i in ("%USERPROFILE%") do (set user=%%i) 2>&1
echo "%user%" > c:\%user%.txt
pause



At last save it a run it and get the log in profile name.