How To Open Elevated Command Prompt With Administrator Privileges In Windows 7 / Vista

There is a security feature in Windows 7 / Vista that comes with User Access Control (UAC) which means processes are launched in restricted mode unless users specifically accept the elevation confirmation. For example running a regsvr32.exe command which is used to register DLL/ActiveX or opening a batch file or script requiring administrative privileges require you to open an elevated Command Prompt. Elevated Command Prompt always run under administrative privileges so users need to launch command prompt will full admin rights and permission state. Here are a few ways to open elevated command prompt.

Method 1

Navigate to Start menu > All Programs > Accessories, here you will see Command Prompt shortcut.

command

Right click on Command Prompt and select Run as Administrator.

right click

Method 2

Go to Start menu.

start

Type cmd in the Search Menu

cmd

Press Ctrl + SHIFT and Click on the cmd shortcut on the Start Menu. Ctrl-Shift-Enter is the general keyboard shortcut that triggers elevation to “Run as Administrator”.

UAC


Press Alt+C from the keyboard or click Continue to confirm the UAC elevation warning prompt and the administrative privileged command prompt will be opened.

admin

Method 3

Create a new desktop shortcut to CMD.EXE

shortcut

To run the shortcut as an administrator by default, right-click the Command Prompt shortcut you created on the Desktop, and choose Properties.

properties

In the Shortcut tab, click Advanced.

advanced

Check the option Run as administrator. Click OK and OK. Now, every time when you double-click the shortcut, command prompt window will open elevated

run as admin

Got any questions, suggestions, or comments? Feel free to leave a comment.

Advertisement
  • rakesh kumar

    dear sir/madam
    i want to know how can i open the command prompt in administrator mode using the batch file………

    actually i want to make a batch file which can open the command prompt in administrator mode…pls help me..

    • Ben Langton

      Here's what I use. It requires PowerShell. Basically, this causes a batch file to call PowerShell to re-run itself in an elevated command prompt. Just paste this at the top of the batch file. It hasn't been extensively tested, but it seems to work.

      :: ****************** Prompt for elevated permissions *************************
      :: This makes the batch file prompt for elevated permissions on Windows Vista
      :: or Windows 7, then re-run itself
      VER | FINDSTR /IL “5.1.” > NUL
      IF %ERRORLEVEL% EQU 0 SET Version=XP

      VER | FINDSTR /IL “5.2.” > NUL
      IF %ERRORLEVEL% EQU 0 SET Version=2003

      VER | FINDSTR /IL “6.0.” > NUL
      IF %ERRORLEVEL% EQU 0 SET Version=Vista

      VER | FINDSTR /IL “6.1.” > NUL
      IF %ERRORLEVEL% EQU 0 SET Version=7

      If “%Version%”==”XP” GoTo SkipElevation
      If “%Version%”==”2003″ GoTo SkipElevation
      PushD “%~dp0″
      If Exist “%~0.ELEVATED” GoTo SkipElevation
      :: Have to escape double quotes because they are passed to Cmd.exe via ShellExecute
      Set CMD_Args=%0 %*
      Set CMD_Args=%CMD_Args:”=”%
      Set ELEVATED_CMD=PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('Cmd.exe', '/C %CMD_Args%', '', 'runas')
      Echo %ELEVATED_CMD% >> “%~0.ELEVATED”
      :: If there are single quotes in the arguments, this will fail
      Call %ELEVATED_CMD%
      Exit
      :SkipElevation
      If Exist “%~0.ELEVATED” Del “%~0.ELEVATED”
      :: ****************************************************************************

      • hashangayasri

        wowwwwwwwwwww thank you lorrdzzzzz

      • Michael Chavarria

        This is great.  Thank you for posting this addition to add.  

  • Ben Langton

    Here's what I use. It requires PowerShell. Basically, this causes a batch file to call PowerShell to re-run itself in an elevated command prompt. Just paste this at the top of the batch file. It hasn't been extensively tested, but it seems to work.

    :: ****************** Prompt for elevated permissions *************************
    :: This makes the batch file prompt for elevated permissions on Windows Vista
    :: or Windows 7, then re-run itself
    VER | FINDSTR /IL “5.1.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=XP

    VER | FINDSTR /IL “5.2.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=2003

    VER | FINDSTR /IL “6.0.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=Vista

    VER | FINDSTR /IL “6.1.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=7

    If “%Version%”==”XP” GoTo SkipElevation
    If “%Version%”==”2003″ GoTo SkipElevation
    PushD “%~dp0″
    If Exist “%~0.ELEVATED” GoTo SkipElevation
    :: Have to escape double quotes because they are passed to Cmd.exe via ShellExecute
    Set CMD_Args=%0 %*
    Set CMD_Args=%CMD_Args:”=”%
    Set ELEVATED_CMD=PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('Cmd.exe', '/C %CMD_Args%', '', 'runas')
    Echo %ELEVATED_CMD% >> “%~0.ELEVATED”
    :: If there are single quotes in the arguments, this will fail
    Call %ELEVATED_CMD%
    Exit
    :SkipElevation
    If Exist “%~0.ELEVATED” Del “%~0.ELEVATED”
    :: ****************************************************************************

  • Ben Langton

    Here's what I use. It requires PowerShell. Basically, this causes a batch file to call PowerShell to re-run itself in an elevated command prompt. Just paste this at the top of the batch file. It hasn't been extensively tested, but it seems to work.

    :: ****************** Prompt for elevated permissions *************************
    :: This makes the batch file prompt for elevated permissions on Windows Vista
    :: or Windows 7, then re-run itself
    VER | FINDSTR /IL “5.1.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=XP

    VER | FINDSTR /IL “5.2.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=2003

    VER | FINDSTR /IL “6.0.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=Vista

    VER | FINDSTR /IL “6.1.” > NUL
    IF %ERRORLEVEL% EQU 0 SET Version=7

    If “%Version%”==”XP” GoTo SkipElevation
    If “%Version%”==”2003″ GoTo SkipElevation
    PushD “%~dp0″
    If Exist “%~0.ELEVATED” GoTo SkipElevation
    :: Have to escape double quotes because they are passed to Cmd.exe via ShellExecute
    Set CMD_Args=%0 %*
    Set CMD_Args=%CMD_Args:”=”%
    Set ELEVATED_CMD=PowerShell -Command (New-Object -com 'Shell.Application').ShellExecute('Cmd.exe', '/C %CMD_Args%', '', 'runas')
    Echo %ELEVATED_CMD% >> “%~0.ELEVATED”
    :: If there are single quotes in the arguments, this will fail
    Call %ELEVATED_CMD%
    Exit
    :SkipElevation
    If Exist “%~0.ELEVATED” Del “%~0.ELEVATED”
    :: ****************************************************************************

    • shruthi

      hello ,

      i have used the above scirpt to open the administrator cmd prompt automatically.

      what i have done is i have a created a separate batch file called common.bat where it will contain the above script as mentioned by you.

      i have used the batch file in other batch file where on click of that batch file it should open the administrator cmd prompt and then it should continue with the installation

      so what i did is i have written the below cmd in the batch file

      start /B cmd /c \\KOR308479\DOORS_ERS\common.bat \\KOR308479\DOORS_ERS\doors93.bat rbin_tst_db profile_mm install > %TEMP%\doors_setup.log 2>&1

      but its not executing it will open the cmd prompt but it will not contiue further

      so kindly do the needfull.

      thank you

      Regards,
      shruthi

  • Yogesh

    i want to delete a file using command prompt in admin account but it is displaying that
    “Access is Denied”…..
    The files i wanted to delete using the command 'del *.*'

  • TheGrunger

    I'm using win7 and this only works with the shortcut in Accessories folder. Any ideas what might help when I run cmd.exe directly through run command? I use commander quite a lot and it's much easier to just press win+R and type three letters than it is to search for a shortcut in start menu.

  • stieven

    Thx for the elevating command. That was were I was looking for!!
    Now I can install and start a service with my batch file without have to worry about admin rights. Will be a lot easier for our users…

  • Shockg

    Ben Langton Thank you. I have been looking for this information for what seems like ages. This will make it easier for my users to run the files.

  • sneha

    Still i have to give username and password..I felt it is like runas command. I want pass password also because i want to run batch file from standard user (who dont have any administrative privilages)

  • Jonathan David Kula

    How do you do this from within command prompt

  • KT
  • venkatesh

    hello
    anybody help me to clear my usb device problem,when i put my flash drive to computer showing usb device not recognise

  • Elvis

    Hi
    I was wondering how to make a batch file that opens up cmd on an administrator level to close a program

    What ive got:
    (AT)echo off
    taskkill /IM (Program name) /f /t

    But when i run it it says it denied because of not having adminitrator privilages

    Can you help??