Page 1 of 1

Create Local User and add to local admin group

Posted: 13 Oct 2021 04:31
by NewDosLearner
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 :)

Re: Create Local User and add to local admin group

Posted: 13 Oct 2021 08:16
by aGerman
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

Re: Create Local User and add to local admin group

Posted: 13 Oct 2021 08:18
by atfon
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?