getting current user's name

Posted on 2014-08-23
Last Modified: 2014-08-27
I need to run a file from the command line. The file is located in desktop folder:

How can I automatically get current user's name and place it in the line above (instead of 'username')?
Question by:axcx
    LVL 3

    Accepted Solution


    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!
    LVL 43

    Expert Comment

    by: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

    LVL 95

    Expert Comment

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

    Expert Comment

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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
    I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now