Add new user account from command line (CMD)

by admin on May 24, 2009

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:

net user username password /ADD

Example: To add a new user account with the loginid John and with password fadf24as

net user John fadf24as /ADD

To add a new user account to the domain:

net user username password /ADD /DOMAIN

Note that the command does not include the domain name.

Example:

net user John fadf24as /ADD /DOMAIN

Rename a user account

We can use below wmic command to rename a user accoun.

wmic useraccount where "name='username' " rename new_username

Ex: To rename the user account techblogger as win7techblogger

wmic useraccount where "name='techblogger' " rename win7techblogger

Net use command does not have any switches to rename a user account.

Few more Advanced uses of net user command.

To specify user full name while creating the user account

net user username userpasswd /ADD /FULLNAME:"User_Fullname"

To specify that the user is allowed to change the password

net user username userpasswd /ADD /PASSWORDCHG:Yes

To restrict user not to change the password:

net user username userpasswd /ADD /PASSWORDCHG:NO

To specify when the account expires we can use /EXPIRES switch.

To specify if the user must  have a password set we can use /PASSWORDREQ switch.

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.
C:\>net user John /add
System error 5 has occurred.
Access is denied.
C:\> 

Related Posts:

{ 12 comments… read them below or add one }

Michael April 20, 2011 at 4:49 am

Possibly the most in-depth article about adding and deleting users by far. Thank you.

Reply

Venkat December 27, 2011 at 2:42 pm

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?

Reply

admin January 10, 2012 at 2:13 pm

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

Padmanabhan January 4, 2012 at 1:26 pm

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.

Reply

Pankaj January 4, 2012 at 1:36 pm

Is it possible to create a new user account without specifying a password?

Reply

JohnG January 17, 2012 at 2:51 pm

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 password /add %time%

It may not work if your password policy is more restrictive.

~ John

Amy March 26, 2012 at 4:18 am

tried this tell’s me it worked then i go switch user and Nothing

Reply

Vanchinathan August 25, 2012 at 7:40 am

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

Reply

admin August 27, 2012 at 7:29 am

Are you doing it from elevated administrator command prompt?

Rathinakumar November 16, 2012 at 6:12 am

Thanks a lot. Simple and solves the purpose immediately.

Reply

dacreman January 30, 2013 at 12:54 am

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

Reply

chiba May 13, 2013 at 3:32 am

Why does mine says access is denied?

Reply

Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: