Link to home
Start Free TrialLog in
Avatar of axcx
axcx

asked on

getting current user's name

I need to run a file from the command line. The file is located in desktop folder:
C:\Users\username\Desktop\file.txt

How can I automatically get current user's name and place it in the line above (instead of 'username')?
ASKER CERTIFIED SOLUTION
Avatar of ebad-it
ebad-it
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Steve Knight
You have your answer anyway... but to add a way to see all these, open a cmd.exe prompt and type the word SET and press return.  You will see all the variables, e.g.

For instance a desktop entry for all users on a Windows 7 PC would be in %public%\desktop

Steve
Actually, while %username% DOES grant the user name, if you are trying to access the user's profile, you should be using the %userprofile% environment variable, not %username% - in case the profile location has changed or runs on Windows XP (which you should be getting rid of).
Lee, ebad-it said that already which is why I didn't elaborate.

Steve