[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

getting current user's name

Posted on 2014-08-23
4
Medium Priority
?
124 Views
Last Modified: 2014-08-27
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')?
0
Comment
Question by:axcx
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
ebad-it earned 2000 total points
ID: 40280724
Hi,

I am not sure what you want a 100%, but to get the user name from a command prompt you can use the variable %USERNAME% to try this open a command window and type "echo %username%" without quotes.

If you want the profile you would use %userprofile% test same as above with echo command.

Let me know if you need more help!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40280925
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
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 40281584
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).
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40281836
Lee, ebad-it said that already which is why I didn't elaborate.

Steve
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question