run 'net user' command as administrator

14,294

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.

Share:
14,294

Related videos on Youtube

abhi120
Author by

abhi120

Updated on September 18, 2022

Comments

  • abhi120
    abhi120 over 1 year

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

    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 almost 12 years
      Runas is a single word.
    • avirk
      avirk almost 12 years
      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*.
    • barlop
      barlop almost 12 years
      @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.
    • avirk
      avirk almost 12 years
      @barlop tried it and yes its in right format its better to check it on your side. :)
    • avirk
      avirk almost 12 years
      And yes I just missed the > after `C:` Its my fault sorry for that but console will not leave it. ;)
    • barlop
      barlop almost 12 years
      @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.
    • Werner Henze
      Werner Henze over 10 years
  • abhi120
    abhi120 almost 12 years
    but i want to run it from windows GUI, not from cmd prompt
  • barlop
    barlop almost 12 years
    @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.
  • TorpedoBench
    TorpedoBench about 10 years
    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.