Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you find the current user in a Windows environment?

People also ask

What command displays the current users username?

d] whoami command – Show current user name.


You can use the username variable: %USERNAME%


Username:

echo %USERNAME%

Domainname:

echo %USERDOMAIN%

You can get a complete list of environment variables by running the command set from the command prompt.


Just use this command in command prompt

C:\> whoami

It should be in %USERNAME%. Obviously this can be easily spoofed, so don't rely on it for security.

Useful tip: type set in a command prompt will list all environment variables.


%USERNAME% is the correct answer in batch and other in Windows environments.

Another option is to use %USERPROFILE% to get the user's path, like C:\Users\username.