In Windows computer we can add users to a group from command line. We can use net localgroup command for this.
net localgroup group_name UserLoginName /add
For example to add a user to administrators group, we can run the below command. In the below example I have taken username as John.
net localgroup administrators John /add
Few more examples:
To add a domain user to local users group:
net localgroup users domainname\username /add
This command should be run when the computer is connected to the network. Otherwise you will get the below error.
H:\>net localgroup users domain\user /add System error 1789 has occurred. The trust relationship between this workstation and the primary domain failed.
To add a domain user to local administrator group:
net localgroup administrators domainname\username /add
To add a user to remote desktop users group:
net localgroup "Remote Desktop Users" UserLoginName /add
To add a user to debugger users group:
net localgroup "Debugger users" UserLoginName /add
To add a user to Power users group:
net localgroup "Power users" UserLoginName /add
This command works on all editions of Windows OS i.e Windows 2000, Windows XP, Windows Server 2003, Windows Vista and Windows 7. In Vista and Windows 7, even if you run the above command from administrator login you may still get access denied error like below.
C:\> net localgroup administrators techblogger /add System error 5 has occurred. Access is denied.
The solution for this is to run the command from elevated administrator account. See How to open elevated administrator command prompt
When you run the ‘net localgroup’ command from elevated command prompt:
C:\>net localgroup administrators techblogger /add The command completed successfully.
To list the users belonging to a particular group we can run the below command.
net localgroup group_name
For example to list all the users belonging to administrators group we need to run the below command.
net localgroup administrators
Related posts:
{ 20 comments… read them below or add one }
How to add a group to another group?
you can use the same command to add a group also. For example, to add a domain group ‘Domain\users’ to local administrators group, the command is:
How can I add a user to a group remotely?
Using pstools, it is a good tools from Microsoft.
While this article is two years old – it still was the first hit when I searched and it got me where I needed to be. Another great tip is the syntax for doing a runas, because I needed to elevate a user's privileges to admin from within his account:
Good stuff.
awesome! I’ve been wanting to know how to do this forever. thanks so much. for some reason, MS has made it impossible to authenticate protected commands via the GUI. seriously frustrating! this makes it all better.
Is there a way to trough a password into the script for the admin account if it is known and generic
How to set password to never expire ?
You can run the below.
Is there any way to add a computer account into the local admin group on another machine via command line? Thanks.
I don’t think that’s possible. However, you can add a domain account to the local admin group of a computer.
Dude, thank you! On xp, the server service was not installed so couldn’t add via manage. User CtrlPnl gpf’s is broke (something about html app host error). In 3 seconds, you provided a way to fix that MS couldn’t with all their idiot wizards…
Hi Reue,
Yes you can add any users to other computers remotely using the pstools.
Hello,
I have a requirement something like this:
I need to create a user account on a remote server which should be a part of the local administrator group. How should i set password for this user account ?
Can any one help me please?
Thanks in advance,
Prashanth
Read this: Add new user account from command line
Using psexec tool, you can run the above command on a remote machine.
I changed the admin account’s rights to user account and now i have only two accounts with only USER rights, nothing with admin. When ever i change any application, it says ” Right Admin Password” and there only comes NO and therefore i am unable to enter Admin Passowrd. Also i m unable to open cmd.exe as Admin. Please Advise.
how can I add multiple domain users into local administrator group together with the single line command?
You can specify as many users as you want, in the same command mentioned above.
For example, to add three users :
I don’t have access to the administrator account, but I do have access to my son’s
Standard Account. Please help.
I am trying to add a service account to a local group but it fails. Is there syntax for that? I’ve tried many variations but no go. See below:
net localgroup “Event Log Readers” “NT Authority\Network Service (S-1-5-20)” /add