Tell me more ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question
1  
Runas is a single word. – techie007 Jun 2 '12 at 18:25
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 '12 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 '12 at 19:37
@barlop tried it and yes its in right format its better to check it on your side. :) – avirk Jun 2 '12 at 23:55
And yes I just missed the > after `C:` Its my fault sorry for that but console will not leave it. ;) – avirk Jun 2 '12 at 23:58
show 1 more comment

1 Answer

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

share|improve this answer
but i want to run it from windows GUI, not from cmd prompt – abhi120 Jun 2 '12 at 18:35
2  
I think key combination for admin is ctrl+shift+enter. – avirk Jun 2 '12 at 18:53
@avirk yeah it is, try it and then you would see and you wouldn't have had to write "I think". Perhaps you're not on a windows 7 machine at the moment in which case that's excusable – barlop Jun 2 '12 at 19:02
@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 '12 at 19:09
@barlop I'm on Windows 7 and yes I'm quite sure that the key combination is right which I told in my comment had tried it with Ctrl+Enter but windows doesn't launch it with admin privilege. – avirk Jun 2 '12 at 23:57
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.