run 'net user' command as administrator

0

I was writing a simple batch file with the following command

net user Abhi *

where Abhi is my username and I am the administrator of my computer. On execution, it prompts for a password and then exits with Access is denied error. I know it requires administrator privileges, but don't know how to do it.

I tried it using:

runas administrator net user abhi *

But it did not work.

How do I run this command successfully (as admin)?

abhi120

Posted 2012-06-02T18:17:07.350

Reputation: 143

1Runas is a single word. – Ƭᴇcʜιᴇ007 – 2012-06-02T18:25:54.280

1First run the command C:\runas /user:username\administrator cmd after this it will ask for password if you have set any type it and if it gives the error then you can try only hit Enter when it prompt for password. Then you can run net user ABhi*. – avirk – 2012-06-02T18:49:53.643

@avirk that runas you wrote doesn't look right. Better to try it in the cmd prompt first then you'd see. Besides missing the > after C:, the way you specified the username looks messed up. See my comment to Kevin's answer, it has a runas command there. – barlop – 2012-06-02T19:37:45.627

@barlop tried it and yes its in right format its better to check it on your side. :) – avirk – 2012-06-02T23:55:01.803

And yes I just missed the > after C:\ Its my fault sorry for that but console will not leave it. ;) – avirk – 2012-06-02T23:58:43.047

@avirk ah you're right that's weird..sorry.. where did you get the notation of /user:username\administrator ? By the way, all you need is /user:Administrator. – barlop – 2012-06-03T00:15:55.793

1

possible duplicate of How to run a program with admin privilege

– Werner Henze – 2014-01-21T09:31:25.410

Answers

1

You said this is a batch file. If you want the batch file to be run with admin privileges, you can just right click it and check the "Run as Administrator" box under the compatibility tab. This will make it acquire admin rights every time you run it.

TorpedoBench

Posted 2012-06-02T18:17:07.350

Reputation: 428

0

If it is Windows 7 type in cmd and use CtrlShiftEnter to get and administrator command prompt then run net user or run your batch from that prompt.

Kevin

Posted 2012-06-02T18:17:07.350

Reputation: 1 873

but i want to run it from windows GUI, not from cmd prompt – abhi120 – 2012-06-02T18:35:47.683

@abhi120 don't know what you're talking about. What he suggests will open cmd with administrative privileges and your net user administrator * command will then work. But if you want to use the runas command then it's runas /user:Administrator c:\windows\system32\cmd.exe But you may need to do net user first anyway to give it a password. so do the ctrl-shift-enter thing. – barlop – 2012-06-02T19:09:24.663

In case this is hard to follow, you can also just search for CMD in the start menu, right click the program, and choose Run as Administrator. – TorpedoBench – 2014-03-27T23:28:39.283

-1

Before net user Abhi * add this cd c:\windows\system32

look like this

cd c:\windows\system32
net user Abhi *

user328431

Posted 2012-06-02T18:17:07.350

Reputation: