Create Local User and add to local admin group

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
NewDosLearner
Posts: 1
Joined: 13 Oct 2021 04:24

Create Local User and add to local admin group

#1 Post by NewDosLearner » 13 Oct 2021 04:31

Hi all,

I am new to creating Bat scripts and I am trying to do something very simple which does not seem to be working.

I am simply trying to create a new local user and add them to the local Administrators group. I am also trying to set the password to never expire.

Below is my code :

net user ADMIN2 ******* /add /active:yes
wmic useraccount WHERE Name='ADMIN2' set PasswordExpires=false
net localgroup Administrators ADMIN2 /add

My code performs the first two lines, but does not add the the user to the local administrators group.

This is probably something very simple.

Thanks for the help in advance :)

aGerman
Expert
Posts: 4291
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Create Local User and add to local admin group

#2 Post by aGerman » 13 Oct 2021 08:16

I don't know if this is the reason, but keep in mind that the NET command expects to get localized names. E.g. the name of the administrators group would be "Administratoren" for my German settings.

Steffen

atfon
Posts: 107
Joined: 06 Oct 2017 07:33

Re: Create Local User and add to local admin group

#3 Post by atfon » 13 Oct 2021 08:18

NewDosLearner wrote:
13 Oct 2021 04:31
net localgroup Administrators ADMIN2 /add

My code performs the first two lines, but does not add the the user to the local administrators group.

This is probably something very simple.

Thanks for the help in advance :)
Your command for net localgroup "looks" correct. Can you run that from the command line directly? If not, do you receive an error? Does it work if you run the batch script as Administrator?

Post Reply