whoami - Check the Current User
The whoami command displays information about the user you are currently signed in as. Besides the user name, it can show group membership, assigned privileges, and the SID (security identifier).
It is handy when you want to confirm whether this Command Prompt is running as administrator, or which user it is running as.
Basic syntax of whoami
whoami [/upn | /fqdn | /logonid]
whoami [/user] [/groups] [/priv] [/fo <format>] [/nh]
whoami /all [/fo <format>] [/nh]
Run without arguments, it shows the current user in domain_name\user_name form.
Check the current user name
whoami
The part before \ is the computer name (or the domain name if you are signed in with a domain account), and the part after it is the user name.
Options at a glance
| Option | What is displayed |
|---|---|
| (none) | domain_name\user_name |
/user | User name and SID |
/groups | Groups the user belongs to, with SIDs |
/priv | Assigned privileges and their state (enabled/disabled) |
/all | All of the above (user, groups, privileges) |
/upn | User name in user@example.com form (domain environments) |
/fqdn | Distinguished name of the user, CN=...,DC=... (domain environments) |
/logonid | Logon session ID |
/fo | Output format: TABLE, LIST, or CSV |
/nh | Hide column headers (for TABLE and CSV) |
/upn and /fqdn are meant for when you are signed in with a domain account, such as in Active Directory. With a local account or a Microsoft account, they report that the current user is not a domain user.
Check the user’s SID
Add /user to display the user name and SID.
whoami /user

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
A SID is a unique ID assigned to each user. It shows up when you look into registry or file permissions.
Check group membership
whoami /groups
This lists the groups the user belongs to, such as Administrators. Headings and attribute descriptions depend on the Windows display language, while group names are often shown in English.
Check assigned privileges
whoami /priv
It shows each privilege name (such as SeShutdownPrivilege), its description, and its state. A state of “Disabled” does not mean the privilege is missing; it means the privilege is available and a program can enable it when needed.
Run whoami /priv in a normal Command Prompt and in one opened as administrator and compare them. The administrator session lists more privileges.
Change the output format
Specifying a format with /fo makes the result easier to process with other commands.
whoami /groups /fo csv /nh
whoami /user /fo list
Check whether you are running as administrator
In a Command Prompt running as administrator, the result of whoami /groups includes the group Mandatory Label\High Mandatory Level (integrity level “High”). Searching for this group’s SID, S-1-16-12288, lets you decide regardless of the display language.
whoami /groups | find "S-1-16-12288"
If a line matches, the session is running as administrator; if nothing is printed, it is running with normal rights.
Test it in a batch file
find returns exit code 0 when a line matches and 1 otherwise, so you can branch with if errorlevel 1.
@echo off
whoami /groups | find "S-1-16-12288" >nul
if errorlevel 1 (
echo Please run this as administrator.
pause
exit /b 1
)
echo Running as administrator.
For automatically elevating to administrator rights, see the related articles.
Use the user name in a batch file
To store the output of whoami in a variable, use for /f.
@echo off
for /f "delims=" %%u in ('whoami') do set CURRENT_USER=%%u
echo Running as: %CURRENT_USER%
If you only need the user name, the environment variable %USERNAME% also works.
| Method | Example result | Characteristics |
|---|---|---|
whoami | desktop-abc123\taro | Includes the domain (or computer) name |
%USERNAME% | taro | User name only. It is an environment variable, so it can be overwritten |
%USERNAME% is an environment variable, so set USERNAME=other_name can change it. When you need to know exactly which user is running, use whoami.
When you run as another user with runas
If you start Command Prompt as another user with runas and run whoami in that window, it shows the user you specified in runas. This helps when you switch between several users and are not sure whose window is open. With /netonly, however, only the credentials used for network connections change and the local user stays the same, so whoami still shows the original user.
Summary
| Goal | Command |
|---|---|
| Check the current user name | whoami |
| Check the SID | whoami /user |
| Check group membership | whoami /groups |
| Check privileges | whoami /priv |
| Show everything | whoami /all |
| Test whether running as administrator | whoami /groups | find "S-1-16-12288" |
| Store the user name in a variable | for /f "delims=" %%u in ('whoami') do ... |