84

Is there a Windows equivalent of Unix "whoami" command? If so, what is it?

2
  • 2
    Yes there is and it's also whoami Sep 1, 2014 at 20:45
  • use the command “query session” to get a list of currently logged in or disconnected terminal services, users
    – Martin
    Feb 27, 2019 at 8:57

7 Answers 7

84

Since Windows 2000, the whoami command has been part of the standard command line (thanks to pk for clearing that up in comments!).

You can do this: Open a command prompt and type "set" then hit enter. This shows active environment variables. Current logged on username is stored in the USERNAME env variable and your domain is stored in the USERDOMAIN variable.

To piggy-back off the other answers, from a cmd line:

echo %USERDOMAIN%\%USERNAME%

will get you the complete logged on user in domain\username format.

You can do the same thing with Powershell with this:

write-host $env:userdomain\$env:username
7
  • 1
    +1 for the educational aspect, and for including the domain as well as the username
    – tomjedrz
    May 19, 2009 at 17:15
  • @squillman How can I make this work when running a command prompt as Sytem user? Cause in that case, there is no environment variable such as %USERDOMAIN% or %USERNAME%
    – GianT971
    Mar 6, 2012 at 14:40
  • @GianT971 Do you mean LocalSystem? There isn't a way for that account since it's not associated with a logged on user. Typically this account is used for services and when a service is running as LocalSystem then it takes on the security context of the service control manager.
    – squillman
    Mar 6, 2012 at 15:47
  • Ok. Yes that's what I meant. Maybe with latest versions of PowerShell it is possible, as when running a .NET app invoking Environment.Username under LocalSystem account, the result is "System". But I have not yet taken a good look at PowerShell
    – GianT971
    Mar 6, 2012 at 17:00
  • @GianT971 You could spawn cmd or powershell processes and run scripts, but you won't get an interactive shell.
    – squillman
    Mar 6, 2012 at 18:23
19

This reports most of the same information that everyone else is saying but you can also just type

SET U

It will return any environment variables that start with U.

As an aside, SET L can be handy for debugging logonserver problems.

1
  • 1
    Somtimes you just see tips that have to be shared, those two are great.
    – Tubs
    May 20, 2009 at 11:00
6

From command line? "echo %username%" should do it. The logged in user is stored in the environmental variable "username".

From a graphical session, ctrl-alt-del will give you a screen with the logged in user displayed.

5

ECHO %USERNAME%

5

It depends on your specific OS, but the whoami command is available as part of the Windows 2000 Resource Kit and Windows XP SP2 Support Tools.

1
  • aha, i thought i had used whoami on my laptop at home recently, i guess it worked because it was vista. here at work i'm on xp
    – Kip
    May 19, 2009 at 19:13
3

The above are native to the OS and better answers, but in the spirit of completeness, there's literally a whoami.exe in the 2000 & XP support tools. At 32 kb, it'd be easy to roll out through group policy, if you had your heart set on that command.

1

In the autoexec, or at a DOS prompt, type prompt %USERDOMAIN%\%USERNAME% $p$g, and you will display who you are logged in as, and see the typical prompt like this: DOMAIM\username C:>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .