whoami - Check the Current User

Maintained on

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
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>whoami
desktop-abc123\taro
C:\users\user>

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

OptionWhat is displayed
(none)domain_name\user_name
/userUser name and SID
/groupsGroups the user belongs to, with SIDs
/privAssigned privileges and their state (enabled/disabled)
/allAll of the above (user, groups, privileges)
/upnUser name in user@example.com form (domain environments)
/fqdnDistinguished name of the user, CN=...,DC=... (domain environments)
/logonidLogon session ID
/foOutput format: TABLE, LIST, or CSV
/nhHide column headers (for TABLE and CSV)
/upn and /fqdn are for domain accounts

/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
- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>whoami /user
USER INFORMATION
----------------
User Name SID
==================== =============================================
desktop-abc123\taro S-1-5-21-1111111111-2222222222-3333333333-1001
C:\users\user>
おすすめ書籍※ 広告を含む場合があります
中小企業経営者のためのRPA入門 RPA導入を成功させる方法

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

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

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

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

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

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかる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.

More privileges are listed when running as administrator

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.

List_groups_in_CSV_format_without_headers
whoami /groups /fo csv /nh
List_items_vertically
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.

- □ ×
Command Prompt Icon
Command Prompt
Microsoft Windows [Version xx.x.xxxxx.xxx]
(c) 2026 Ribbit App Development All rights reserved.
 
C:\users\user>whoami /groups | find "S-1-16-12288"
Mandatory Label\High Mandatory Level Label S-1-16-12288 …
C:\users\user>

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.

admin-check.cmd
@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.

current-user.cmd
@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.

MethodExample resultCharacteristics
whoamidesktop-abc123\taroIncludes the domain (or computer) name
%USERNAME%taroUser name only. It is an environment variable, so it can be overwritten
%USERNAME% 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

GoalCommand
Check the current user namewhoami
Check the SIDwhoami /user
Check group membershipwhoami /groups
Check privilegeswhoami /priv
Show everythingwhoami /all
Test whether running as administratorwhoami /groups | find "S-1-16-12288"
Store the user name in a variablefor /f "delims=" %%u in ('whoami') do ...

Practice questions

Practice Problem

Which command lists the groups the current user belongs to?

回答がサーバーに送信されることはありません
Practice Problem

Which statement about the difference between %USERNAME% and whoami is correct?

回答がサーバーに送信されることはありません
#Command Prompt #Batch Files #Command Line #Commands #User #Administrator Rights