1

runas /profile /user:administrator "cmd /c net user /add [username] [password]".

I used the above command to create a new user using administrator permissions. After I enter this command, it prompts me for the administrator's password and when I input the password it creates the new user.

But I don't want to manually sit and type in the password. Is it possible to automatically pass in the password when prompted?

I tried the following command, but it gives me an error.

echo abcd | runas /profile /user:administrator "cmd /c net user /add [username] here, abcd is the administrators password.

the error I get is:

C:\Users\pjs>echo abcd | runas /profile /user:administrator "cmd /c net user /add joe hello"

Enter the password for administrator:

Attempting to start cmd /c net user /add joe hello as user "administrator" ...

RUNAS ERROR: Unable to run - cmd /c net user /add joe hello 1326: The user name or password is incorrect.

Is there any other way to solve this.

1 Answer 1

1

You could use one of the runas switches as long as the password doesn't change:

runas /user:administrator /savecred "cmd /c..."

The first time you run this it'll ask you for the password, subsequent times it'll not prompt you for the password as long as you specify the savecred switch and as long as the password doesn't change.

1
  • Can it not pass the password every time. Like save the password in a file and when it prompts for a password it should read the file.. Something of that sort. I have no idea about the syntax which could be used.
    – pjs
    Commented Mar 19, 2015 at 11:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .