On Windows 7, is there a command prompt line that can start cmd as an administrator?

142,682

Solution 1

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\USERNAME 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).

Solution 2

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%

Solution 3

Another alternative is to click Start and type cmd, followed by Ctrl + Shift + Enter

Source: Microsoft Technet

Solution 4

Use SuRun.

It works on Windows 8 as well. It runs the application in "admin" mode without a prompt, yet you have greater control on what applications are run (you can see it on the SuRun's control panel applet). It works great in a batch file too...

Solution 5

If you want a command-line solution: download hstart from http://www.ntwind.com/software/hstart.html and extract hstart.exe or hstart64.exe to somewhere on your path. You can start an elevated command prompt with hstart /runas cmd or hstart64 /runas cmd.

But the fastest way (as noted in a comment for the question) is still to press Windows, type cmd and press Ctrl + Shift + Enter.

Share:
142,682

Related videos on Youtube

GeekAbhiGeek
Author by

GeekAbhiGeek

I started with Apple Basic and 6502 machine code and Assembly, then went onto Fortran, Pascal, C, Lisp (Scheme), microcode, Perl, Java, JavaScript, Python, Ruby, PHP, and Objective-C. Originally, I was going to go with an Atari... but it was a big expense for my family... and after months of me nagging, my dad agreed to buy an Apple ][. At that time, the Pineapple was also available. The few months in childhood seem to last forever. A few months nowadays seem to pass like days. Those days, a computer had 16kb or 48kb of RAM. Today, the computer has 16GB. So it is in fact a million times. If you know what D5 AA 96 means, we belong to the same era.

Updated on September 17, 2022

Comments

  • GeekAbhiGeek
    GeekAbhiGeek over 1 year

    On Linux, we can use

    sudo bash
    

    to run a shell as the superuser.

    On Windows 7, we can use

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

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

    • Julian
      Julian over 14 years
      You can also search for cmd (like you already do) and press "ctrl+shift+enter" to launch the selected program as administrator.
  • Julian
    Julian over 14 years
    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.
  • GeekAbhiGeek
    GeekAbhiGeek over 14 years
    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?
  • user1686
    user1686 over 14 years
    Joshua: Unless you use /savecred.
  • MDMoore313
    MDMoore313 about 11 years
    +1, and for local admin runas /user:administrator cmd.exe is not hard to remember after a dozen types or so. All it is is the command itself runas followed by the /user: switch, followed by the user we want to run it as, then finally the program we want to run, cmd.exe (the command prompt in our case). This is as close to a one line you can get for running command prompts elevated. Also, if you do start->run sometimes there's a checkbox to run the program elevated, I haven't put any effort into figuring out what makes it appear, but it is an option.
  • Wolf
    Wolf over 9 years
    just a note for Windows 8 (and 8.1): I was not able to launch a command prompt as admin, because surun replaces - by default settings - the built-in runas function in the context menus.
  • TOOGAM
    TOOGAM about 9 years
    This results in prompting user with UAC dialog box, and then running the desired command in a separate window.
  • CodeManX
    CodeManX over 8 years
    But what is the administrator password? It doesn't accept a blank one. If I right-click > Run as administrator, it doesn't ask me for a password (possibly because my user account has admin privileges, but this is different from run as admin, which will run with elevated rights).
  • CMCDragonkai
    CMCDragonkai about 8 years
    It appears that by default the administrator does not have a password. And that the account is actually disabled. The administrator account needs to be first enabled, given a password and then it becomes an actual user that you can log into and runas into.
  • Dasha
    Dasha almost 6 years
    This works great - just say sudo <command> and hit Alt+Y in the UAC dialog.