vote up 3 vote down star

On Linux, we can use

sudo bash

to run a shell as the superuser

On Windows 7, we can use

START -> (in search box, type) cmd -> Right click on search result and choose Run as Administrator

to run a command prompt as an admin. Is there also a command prompt line that is like Linux's sudo or su so as to start a shell as an admin?

flag

20% accept rate
3  
You can also search for cmd (like you already do) and press "ctrl+shift+enter" to launch the selected program as administrator. – Joshua Nov 24 at 2:18

4 Answers

vote up 5 vote down

The runas command is the closest thing to what you're looking for:

runas /user:username cmd.exe

The format is runas, the username you want to run as, other options, and then the program you want to run.

If you're on a domain, you can use:

runas /user:DOMAIN\Administrator cmd.exe

This can be run from the Run box ( Win+R ) or from a command window.

Note, however, that this is not exactly like sudo - you can't use it to elevate yourself, just run something as a different user. If you're already have administrative rights, a runas to your account will give you the same access as the regular command (unless, of course, you runas a different administrator account, which will grant those administrator's rights to the new shell).

link|flag
Also, unlike sudo, runas will never cache the password for any length of time. So if you were planning on queuing up a couple quick commands like you can with successive runs of sudo. So just open a console window and run your commands there. – Joshua Nov 24 at 2:26
so the shortest form is "runas /user:DOMAIN\Administrator cmd.exe" wow... that's pretty long and hard to remember... and i can create an alias, but what if i am on someone else's computer and helping out? will it be a good idea if MS can create a special command called runasadmin? – Jian Lin Nov 24 at 9:23
Joshua: Unless you use /savecred. – grawity Nov 24 at 18:19
vote up 1 vote down

I don't know about Win7..

Try creating a shortcut to cmd.exe. Right Click > Properties. Click on Advanced button. And tick the box "Run as Administrator" and click OK.

Assign it a shortcut key if you want.

And you could also assign the default location for the CMD prompt to start in.. eg %CD%

Hope this of some help.

link|flag
vote up 0 vote down

You might like Sudo for Windows (but I haven't tried it yet)

link|flag

Your Answer

Get an OpenID
or
never shown

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