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)?

7
  • 1
    Runas is a single word. Jun 2, 2012 at 18:25
  • 1
    First 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
    Jun 2, 2012 at 18:49
  • @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
    Jun 2, 2012 at 19:37
  • @barlop tried it and yes its in right format its better to check it on your side. :)
    – avirk
    Jun 2, 2012 at 23:55
  • 1
    possible duplicate of How to run a program with admin privilege Jan 21, 2014 at 9:31

3 Answers 3

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.

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.

3
  • but i want to run it from windows GUI, not from cmd prompt
    – abhi120
    Jun 2, 2012 at 18:35
  • @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
    Jun 2, 2012 at 19:09
  • 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. Mar 27, 2014 at 23:28
-1

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

look like this

cd c:\windows\system32
net user Abhi *

You must log in to answer this question.

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