Wednesday, November 10, 2010

XP Batch Files Can Create Variables For Users Who Log In



This is a quick batch file tips, these tips just a quick batch file that allows you to find users who are logged on as a batch file is executed by using the FOR statement and the% USERPROFILE% variabe in XP.

This batch file will do the following below:

find users who are logged in at this time when the file is run the setup of a variable, the user, whose value will be assigned to user login
and then echo back to user login.

@ 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 the orders of another batch file. If you want this information put into a text file, you simply use this command.

@ Echo off
for / f "tokens = 3 delims ="%% i in ("% USERPROFILE%") do (set user =%% i) 2> & 1
echo "% user%"> c:% user%. txt
pause

so let's say we will log on as a john, a file named john.txt will be created and the user login file 'john' will be residing. Command line can be modified and used for various things such as copying files to a user's desktop or documents or anything where you need to use that user account.

No comments:

Post a Comment