Get current logged in user name command line (CMD)

by admin on October 28, 2010

In Windows OS, we can find the current logged in username from windows command line. The logged in user information is stored in environment variables. So just by printing the value in these environment variables we can get to know the login name.

To know the login name of the currently logged in user we can run the below command.

echo %username%

This works on all releases of Windows OS(Windows XP, Server 2003, Windows Vista and Windows 7).

There is another command whoami which tells us the domain name also.

whoami

Example:

c:\>whoami
cmdline\administrator

Both of these options to find user name can be useful in batch files to write code in such a way that it works for every user. For example, if your batch file need to access a user specific folder, say Application data, then you can refer the directory as ‘C:\users\%username%\appdata‘.

{ 6 comments… read them below or add one }

Anonymous June 22, 2011 at 8:17 am

how to know the current user password in windows 7?

Reply

sujan pandit April 22, 2012 at 7:41 pm

run cmd in admin mode and type net user (user name) (12345)
then your password change to 12345

Techblogger June 23, 2011 at 9:36 am

I don't think it would be possible to find the password as it is stored in encrypted form and not in plain text. However, there are lots of third party tools to reset a administrator password if you have forgotten the same.

Reply

jimmy March 27, 2012 at 11:53 pm

when i go onto command promt it says my username is “user” and say c:/users>user

Reply

David DeLella September 17, 2012 at 12:57 pm

The whoami command does not work in Windows XP without the SP2 Support Tools download. The command is not native to the OS. http://www.microsoft.com/en-us/download/details.aspx?id=18546

Reply

moke November 11, 2012 at 4:00 am

thanks bro

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: