Is there a Windows equivalent of Unix "whoami" command? If so, what is it?
-
2Yes there is and it's *also* `whoami` – DeepSpace101 Sep 01 '14 at 20:45
-
use the command “query session” to get a list of currently logged in or disconnected terminal services, users – Martin Feb 27 '19 at 08:57
7 Answers
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

- 37,883
- 12
- 92
- 146
-
1+1 for the educational aspect, and for including the domain as well as the username – tomjedrz May 19 '09 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 06 '12 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 06 '12 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 06 '12 at 17:00
-
@GianT971 You could spawn cmd or powershell processes and run scripts, but you won't get an interactive shell. – squillman Mar 06 '12 at 18:23
-
This answer is obviously useful, but I would like to point out that `whoami` is not a PowerShell command. It's been around since Win2K and is part of the standard Windows command line. – pk. Mar 13 '13 at 21:19
-
@pk I thought I'd seen that it was Powershell specific but of course, you're absolutely right. I've edited that into the answer and removed the bit about it being specific to Powershell. Thanks for pointing that out! – squillman Mar 13 '13 at 22:50
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,539
- 2
- 13
- 23
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.

- 133,124
- 18
- 176
- 300
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.

- 423
- 1
- 6
- 17
-
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 '09 at 19:13
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.

- 7,892
- 5
- 33
- 57
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:>

- 11
- 1