Get current logged in user name command line (CMD)
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.
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.
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‘.
how to know the current user password in windows 7?
run cmd in admin mode and type net user (user name) (12345)
then your password change to 12345
Use this command:
net user “%username%” “%random%%random%%random%%random%%random%”
Suggestion to use command:
net user “%username%” “%random%%random%%random%%random%%random%”
will change your current users password to something completely random
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.
when i go onto command promt it says my username is “user” and say c:/users>user
I HAVE THE SAME PROBLEM. HAVE YOU SOLVE YOUR PROBLEM YET?
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
Can the %username% command be used to determine the user logged into a differnent computer. ex I am at computer x and want to know who is logged on to computer y. I can remote to the c drive using RDP \\computery\c$ I would also like to definively likt to know who is logged on to that computer. Possible?
No, it does not work that way. %username% always shows the user of the current login session. When you run it on remote computer, I am not sure what you would get but it won’t tell you who logged on to the machine.
You can use PSEXEC to run a command on another PC. It can be found in the PS Tools package available for download on many sites.
With System Internal tools (free http://technet.microsoft.com/en-us/sysinternals/bb897545.aspx )
psloggedon \\targetComputer
or
psloggedon \\192.167.0.0
Is it possible to get current User Name when it’s an AD where each user has an ID?
For example, if I run whoami or %username% I get “XX00000” but I want to get “Name SecondName”. I know windows has this info because I see my full name in Start Menu (Win 7).
Thanks
net user %username% for accounts stored in local or net user %username% /domain for accounts stored on domain.
you know this answer…?… anyone please let me know solution for georges’ question.. thanks in advance..
I would also really like a solution for this
If you are asking to find the full name or Surname run this as administrator.
net user
It will show you all the information about that user, full name, logon time, the group this user belongs to, the time it is allowed to login all of that.
When I run whoami from the cmdline I get my username. However I want to find my username from within SQL Server. If I shell out and run whoami I get the sql service user . Any ideas?
what username lets you look at the history
what does it mean by username
Please show screen shot
I have 2 accounts one for me and one for my nephews and nieces so I forgot my password because it makes me change it every other month it seems like and idk why… but I looked up a way to change it by going into the command prompts but it’s only giving me the kids for net user it says mine doesn’t exist I could use some help asap
I need to find my administrator account password when its logged in so is there way i can do it from cmd to find my password without changing it ?
does we have a vraiable like %username% for user group name ?
query user query user
Область применения: Windows Server (половина ежегодного канала), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012 Applies to: Windows Server (Semi-Annual Channel), Windows Server 2019, Windows Server 2016, Windows Server 2012 R2, Windows Server 2012
Отображает сведения о пользовательских сеансах на удаленный рабочий стол сервере узла сеансов. Displays information about user sessions on a Remote Desktop Session Host server. С помощью этой команды можно определить, вошел ли конкретный пользователь на конкретный сервер узла сеансов удаленный рабочий стол. You can use this command to find out if a specific user is logged on to a specific Remote Desktop Session Host server. Эта команда возвращает приведенные ниже сведения. This command returns the following information:
Имя пользователя Name of the user
Имя сеанса на удаленный рабочий стол сервере узла сеансов Name of the session on the Remote Desktop Session Host server
Идентификатор сеанса Session ID
Состояние сеанса (активно или отключено) State of the session (active or disconnected)
Время простоя (количество минут с момента последнего нажатия клавиши или перемещения мыши в сеансе) Idle time (the number of minutes since the last keystroke or mouse movement at the session)
Дата и время входа пользователя Date and time the user logged on
Чтобы узнать о новых возможностях последней версии, см. статью новые возможности службы удаленных рабочих столов в Windows Server. To find out what’s new in the latest version, see What’s New in Remote Desktop Services in Windows Server.
Синтаксис Syntax
Параметры Parameters
Параметр Parameter | Описание Description |
---|---|
Указывает имя входа пользователя, которому необходимо выполнить запрос. Specifies the logon name of the user that you want to query. | |
Указывает имя сеанса, с которым необходимо выполнить запрос. Specifies the name of the session that you want to query. | |
Указывает идентификатор сеанса, к которому необходимо выполнить запрос. Specifies the ID of the session that you want to query. | |
/server: /server: | Указывает удаленный рабочий стол сервер узла сеансов, к которому требуется выполнить запрос. Specifies the Remote Desktop Session Host server that you want to query. В противном случае используется текущий сервер узла сеансов удаленный рабочий стол. Otherwise, the current Remote Desktop Session Host server is used. Этот параметр является обязательным только при использовании этой команды с удаленного сервера. This parameter is only required if you’re using this command from a remote server. |
/? /? | Отображение справки в командной строке. Displays help at the command prompt. |
Комментарии Remarks
Чтобы использовать эту команду, необходимо иметь разрешение на полный доступ или специальное разрешение доступа. To use this command, you must have Full Control permission or special access permission.
Если вы не укажете пользователя, используя параметры , или SessionID , возвращается список всех пользователей, вошедших в систему на сервере. If you don’t specify a user using the , , or sessionID parameters, a list of all users who are logged on to the server is returned. Кроме того, можно также использовать команду запросить сеанс для вывода списка всех сеансов на сервере. Alternatively, you can also use the query session command to display a list of all sessions on a server.
Когда пользователь запроса возвращает сведения, (>) перед текущим сеансом отображается символ «больше чем». When query user returns information, a greater than (>) symbol is displayed before the current session.
Примеры Examples
Чтобы отобразить сведения обо всех пользователях, вошедших в систему, введите: To display information about all users logged on the system, type:
Чтобы отобразить сведения о пользователе User1 на сервере Server1, введите: To display information about the user USER1 on server Server1, type:
Add new user account from command line (CMD)
Some times we may want to add new users from command line instead of using the UI. For example, if we have to add some 100 users, using a script will save lot of time and manual effort. Windows provides net user command for this purpose. This command works on Windows 2000, Windows XP/2003, Vista and Windows 7.
To add a new user account on the local computer:
Example: To add a new user account with the loginid John and with password fadf24as
Hide password
If you do not want the password to be visible while adding new user account, you can use ‘*’ as shown below.
To add a new user account to the domain:
Note that the command does not include the domain name.
Rename a user account
Net use command does not have any switches to rename a user account. But we can do that using wmic commands. Please check this – Rename user accounts on Windows
Few more Advanced uses of net user command.
To set user full name while creating the user account
To allow user to change password:
To restrict user not to change the password:
To set account expiry time we can use /EXPIRES switch. This can also be used to set that the account never expires.
To specify if the user must have a password set we can use /PASSWORDREQ switch. For more information on all net user options, read this – Net user command: syntax and examples
How to create a new administrator account?
An administrator account can’t be created directly. We first need to create a user account and then add the user to the administrators group.
Errors:
- If you don’t have privileges to add new user account to the system, you would get an error like below.
- While adding user to domain, make sure that your computer is connected to the domain. Otherwise it throws up below error.
Related Posts:
Possibly the most in-depth article about adding and deleting users by far. Thank you.
Is there a command/script to create a user in multiple servers at a time, also give him a mandatory chance to change his login password once he logs in the next time, in Windows Server 2003 OS?
You need to run your script on each of the servers. To make it mandatory to change the password, you can use the switch /LOGONPASSWORDCHG.
Command is:
net user loginname password /add /LOGONPASSWORDCHG:yes
Thanks for sharing this. I need to write a batch file to create users through command line. Your tip has helped me. This site is very useful for command prompt users on windows.
Is it possible to create a new user account without specifying a password?
I’m not aware of a way to create user acounts without a password and I wouldn’t recommend it. However I would suggest you could use a randomly generated string to use as the password when the account is created. Or how about the current system time using %time%. For example:
net user loginname %time% /add
It may not work if your password policy is more restrictive.
It is possible
Just type:
Net user Username /ADD
tried this tell’s me it worked then i go switch user and Nothing
thats because you need to login to your account say you had 2 accounts 1 admin the other not you would create the new account dosnt show login to the non admin 1 the lock it u will the find it by pressing swithch user
iam having a username as the member of administrator group. but while using to add a user acc in command prompt it shows the error as system error 5 has occured access denied.
can anyone help this
Are you doing it from elevated administrator command prompt?
Thanks a lot. Simple and solves the purpose immediately.
I am using the /EXPIRES:NEVER switch on the end of the command, however the Never Expires checkbow is not ticked when i check the properties
/Expires switch is for the account but not for the password. /Expires:Never actually sets your a/c not to expire, but not for the password.
Why does mine says access is denied?
Make sure that you have administrator privileges to add new user account.
is it possible to create a user from command promt with normal user
No. Only users with admin privileges can add new users.
Can you please tell me. How to create bulk user in local machine user name & password with Never EXPIRES ..
You can use for loop and create user accounts in bulk.
Check this: For loop examples
wmic path Win32_UserAccount WHERE Name=’PUT_USER_NAME_HERE’ set PasswordExpires=false
Thanks for this article! You have saved me!!
Ciao from Italy
Hey, sorry to ask but how do i get past the System Error 5?
I am on the only Admin account on my lapyop, but it still only says that whenever i try to change anythimg abouy accounts.
Hey, did you tried to lunch command promt: right-click>run as administrator?
You need to check the reply given by admin:
*********************
admin August 27, 2012 at 7:29 am
Are you doing it from elevated administrator command prompt?
************************************************
For elevated command prompt , the below link might be helpful to you
http://www.windows-commandline.com/elevated-command-prompt/
How do I create a local user account on a Domain server? Is there a command that I can use? There is no facility to add a local account on a Domain machine. Please assist
This scenario well describes my issue. How can I get admin. privileges using the embedded Administrator?
An administrator account can’t be created directly. We first need to create a user account and then add the user to the administrators group.
If you don’t have privileges to add new user account to the system, you would get an error like below.
C:\>net user John /add
System error 5 has occurred.
Access is denied.
C:\>
I followed the instructions for command prompt. Keep getting the message: “is not recognized as an internal or external command, operable program or batch file”
I do not have the right click option on command. Have to type Command Prompt in search to to open, then type in the command line which gives me the above posted result.
Hold CTrl and shift together then click on cmd icon after you search it .
This should open as admin.
Fixes your right click problem .
How do you get rid of “system error 5 has occurred” and make me to be able to use commands
Niels, please read the comments, this question was answered 5 times already – hint: elevated privileges.
Command ran successfully – But user directory structure is not there.
For example, under Documents and Settings there is not a directory of the new users Name.
Does the user have to login once for that to be created ?
Yes, account must be logged into to make default profile for user.
My Windows could not start up normally.
And with recovery I needed to login with an user account. But Windows did not see my one account. (that account have administrator access). So what I have done. Next: rebooted my pc into safe mode with cmd
In cmd I made an new administrator account.
Using this cmd code: net username password /ADD
Then i rebooted my pc into advanced recovery. Where I used the option:
Bring Windows back to a restore point.
And logged in with the account I made in cmd.
This helped for me
for creating the user id in local server below is the commend
net user arul “[email protected]″ /ADD /FULLNAME:”James areul” /comment:”server support enginer” /LOGONPASSWORDCHG:yes
I know that you need to be an administrator to run the commands.If you don’t have privileges , you would get an error like below.
System error 5 has occurred.
Access is denied.
I want to query the groups of the user remotely.
net user John /domain
I am able to run this command when i run it via rdp.
But when the same is done via powershell with the administrator, it still gives me a Access is denied error.
How can i resolve this ?
Thanks to your answer. I am also need how to create admin user account with password using CMD-line. Note that when I create it, the password must hidden when I write the password.
Thank you for Your Help me.
Added command in the post to hide the password. Check this out.
Adding admin account is done in two steps, first add user account and then give admin privileges to the account.
But can you add a Microsoft Account with command com?
Useful information here. Keep it up.
Is it possible to use this command to create a user on another machine other than the one you’re actually on when machines are in a workgroup and not on a domain?
Hello Andrew, looking at the syntax the ‘net user’ command supports, I do not think that it can handle workgroup scenario. I would suggest you to try psexec tool by Microsoft.
This was very helpful. 🙂
I came across this article and wondered if maybe you could help. I created a local account for my son on my laptop but I cannot open it every time I try it says logging out. So I tried creating his account as set up in your article and it’s still doing the same I had windows 8 then 8.1 and now 10 and since I updated to 10 I have not been able to access his account I have deleted and added it several times each a different way with no success on any of them. Every thing is up to date and I even ran some kind of system check on it any advice?
In my laptop, I forget the password. How can I set a new user through cmd in safe mode and how I retrieve the data which has been saved in Old User.
I recently bought a laptop that automatically logs in on start up to the standard account, but also has an admin account. Log off and Switch Users don’t allow me to change accounts, it just logs right back in to the standard user account. Tried using runas /user:USername cmd to try and enable elevated privileges, but password is not being accepted. Any ideas?
How long until the commands that create a new domain user and the one that adds it to the domain admins group will take. Iam required to know but I dont have an access to a network to test it.
The commands should finish in few seconds.
Do you know if it is possible to create a small script that would create a standard user with the name taken from the PC-NAME?
I am thinking I would need to use the equivalent of grep for windows? I would need to check to see if there was a command to show computer name, maybe output it to a file and then pull the information from it?
Anyone come across anything like this?
Can you please assist. I was adding an new user on cmd and I did a mistake I only included the username not the password like this “net user (username) /ADD”. then when I try to log in it needs the password while I didn’t set it, and now I’m in trouble please help.
Can you please assist. I have been created a new user my leptop using cmd and I did not included the password like this ” net user ( username ) / ADD “. then when I try to log in to the user it needs password while I didn’t set it.
Does it create a account with admin permissions or standard account permissions…
Newly created user gets automatically deleted on restart, created in cmd access from advanced startup f8.
Is windows 8 very stupid, or am i doing anything wrong?
This works but when you add it in the administrators group. It wont be like a “real admin” account. When you launch cmd it wont start “as admin”
Test comment from Giri 1
Good afternoon! I’ve seen that it is possible to create a user for a certain domain by cmd, but wanted to know if you have how to enter the user soon in a domain group, is it possible?