≡ Menu

Get current logged in user name command line (CMD)

In Windows OS, we can find the current logged in username from windows command line. The logged in user information is stored in environment variables. So just by printing the value in these environment variables we can get to know the login name.

To know the login name of the currently logged in user we can run the below command.

echo %username%

This works on all releases of Windows OS(Windows XP, Server 2003, Windows Vista and Windows 7).

There is another command whoami which tells us the domain name also.

whoami

Example:

c:\>whoami
cmdline\administrator

Both of these options to find user name can be useful in batch files to write code in such a way that it works for every user. For example, if your batch file need to access a user specific folder, say Application data, then you can refer the directory as ‘C:\users\%username%\appdata‘.

20 comments… add one
  • Anonymous

    how to know the current user password in windows 7?

    • sujan pandit

      run cmd in admin mode and type net user (user name) (12345)
      then your password change to 12345

    • Hacker

      Use this command:
      net user “%username%” “%random%%random%%random%%random%%random%”

      :D

    • Ignore Suggestion From "Hacker"

      Suggestion to use command:
      net user “%username%” “%random%%random%%random%%random%%random%”
      will change your current users password to something completely random

  • Techblogger

    I don't think it would be possible to find the password as it is stored in encrypted form and not in plain text. However, there are lots of third party tools to reset a administrator password if you have forgotten the same.

  • jimmy

    when i go onto command promt it says my username is “user” and say c:/users>user

    • LIANA

      I HAVE THE SAME PROBLEM. HAVE YOU SOLVE YOUR PROBLEM YET?

  • David DeLella

    The whoami command does not work in Windows XP without the SP2 Support Tools download. The command is not native to the OS. http://www.microsoft.com/en-us/download/details.aspx?id=18546

  • moke

    thanks bro

  • lynsean

    Can the %username% command be used to determine the user logged into a differnent computer. ex I am at computer x and want to know who is logged on to computer y. I can remote to the c drive using RDP \\computery\c$ I would also like to definively likt to know who is logged on to that computer. Possible?

    • admin

      No, it does not work that way. %username% always shows the user of the current login session. When you run it on remote computer, I am not sure what you would get but it won’t tell you who logged on to the machine.

    • ANON

      You can use PSEXEC to run a command on another PC. It can be found in the PS Tools package available for download on many sites.

  • Omar Alvarez

    With System Internal tools (free http://technet.microsoft.com/en-us/sysinternals/bb897545.aspx )
    psloggedon \\targetComputer
    or
    psloggedon \\192.167.0.0

  • Georges

    Is it possible to get current User Name when it’s an AD where each user has an ID?
    For example, if I run whoami or %username% I get “XX00000” but I want to get “Name SecondName”. I know windows has this info because I see my full name in Start Menu (Win 7).
    Thanks

    • Andrei

      net user %username% for accounts stored in local or net user %username% /domain for accounts stored on domain.

    • morajse

      you know this answer…?… anyone please let me know solution for georges’ question.. thanks in advance..

  • markj

    When I run whoami from the cmdline I get my username. However I want to find my username from within SQL Server. If I shell out and run whoami I get the sql service user . Any ideas?

  • anonymous

    what username lets you look at the history

  • anonymous

    what does it mean by username

  • Dipak Kumar Chhibramau

    Please show screen shot

Leave a Comment