Hotkey to open cmd with administration rights in current folder from Explorer

Learn hotkey to open cmd with administration rights in current folder from explorer with practical examples, diagrams, and best practices. Covers windows-10, keyboard-shortcuts, shortcut developmen...

Hotkey to Open Command Prompt as Administrator in Current Folder

Hero image for Hotkey to open cmd with administration rights in current folder from Explorer

Learn how to quickly open an elevated Command Prompt directly in your current Explorer directory using keyboard shortcuts and custom registry edits.

Opening a Command Prompt (CMD) with administrative rights is a common task for developers, system administrators, and power users. While Windows offers several ways to do this, navigating to a specific directory can be cumbersome. This article provides methods to streamline this process, allowing you to open an elevated CMD directly in your current Explorer folder with a simple hotkey or context menu option.

Understanding the Challenge

By default, Windows Explorer's built-in 'Open PowerShell window here' (or 'Open command window here' in older versions) does not launch with administrative privileges. To run commands that require elevated permissions, you typically have to:

  1. Open CMD as Administrator from the Start Menu.
  2. Manually navigate to the desired directory using cd commands.

This two-step process can be inefficient, especially when frequently working in different project folders. Our goal is to bypass the manual navigation and directly launch an elevated CMD in the active Explorer path.

flowchart TD
    A[User in Explorer] --> B{Needs Admin CMD in Current Folder?}
    B -->|No| C[Use Standard CMD/PowerShell]
    B -->|Yes| D[Current Windows Behavior]
    D --> D1[Open Admin CMD (Start Menu)]
    D1 --> D2[Manually CD to Folder]
    D --> E[Desired Behavior]
    E --> E1["Hotkey/Context Menu (Admin CMD Here)"]
    E1 --> F[Admin CMD Opens in Current Folder]
    style D fill:#f9f,stroke:#333,stroke-width:2px
    style E fill:#bbf,stroke:#333,stroke-width:2px

Comparison of default vs. desired workflow for opening an elevated Command Prompt.

Method 1: Using a Registry Hack for Context Menu

The most robust way to achieve this is by adding a custom entry to the Windows Explorer context menu (the menu that appears when you right-click). This method involves modifying the Windows Registry, which should be done with caution. Always back up your registry before making changes.

1. Open Registry Editor

Press Win + R, type regedit, and press Enter. Confirm the User Account Control (UAC) prompt.

2. Navigate to the Target Key

In Registry Editor, navigate to: HKEY_CLASSES_ROOT\Directory\shell

3. Create a New Key for Your Command

Right-click on shell, select New > Key, and name it runascmd (or any descriptive name like OpenAdminCmd).

4. Set the Display Name

With runascmd selected, in the right pane, double-click the (Default) value and set its data to Open Command Prompt as Administrator Here.

5. Add an Icon (Optional)

Right-click runascmd, select New > String Value, name it Icon, and set its data to cmd.exe (or C:\Windows\System32\cmd.exe).

6. Create the Command Key

Right-click on runascmd, select New > Key, and name it command.

7. Define the Command Execution

With command selected, double-click the (Default) value in the right pane and set its data to: cmd.exe /s /k pushd "%V"

This command launches cmd.exe with administrative privileges (inherited from the runas verb, which we'll add next) and uses pushd "%V" to change the directory to the current Explorer path (%V).

8. Add the 'runas' Verb

Go back to the runascmd key (the parent of command). Right-click on runascmd, select New > String Value, and name it Extended. Leave its data empty. This makes the option appear only when you hold Shift and right-click. If you want it to always appear, skip this step.

9. Apply to Background (Optional)

To make this option available when right-clicking on the background of a folder (not on a file or subfolder), repeat steps 3-7 under HKEY_CLASSES_ROOT\Directory\Background\shell instead of HKEY_CLASSES_ROOT\Directory\shell.

Method 2: Using a Batch Script and Shortcut (Hotkey)

While the registry hack provides a context menu entry, creating a direct hotkey requires a slightly different approach, often involving a batch script and a shortcut. This method doesn't directly integrate with Explorer's 'current folder' concept for a hotkey, but it can be adapted to open CMD in a predefined folder with admin rights, or you can combine it with the registry method for context menu access.

@echo off
cd /d "%1"
cmd.exe /k

A simple batch script (open_admin_cmd.bat) to change directory and open CMD.

This batch script, however, won't automatically elevate. To get administrative rights, you'd typically need to run the batch file itself as administrator, or use a more complex VBScript/PowerShell wrapper to invoke runas.

For a true 'hotkey to admin CMD in current folder' experience, the registry method combined with the Shift + Right-Click functionality is the closest native solution. If you need a global hotkey, you would typically create a shortcut to cmd.exe (configured to 'Run as administrator' in its properties) and assign a hotkey to that shortcut. However, this shortcut would always open in a fixed directory (e.g., C:\Windows\System32) unless you manually change the 'Start in' property of the shortcut, which defeats the 'current folder' aspect.

Alternative: PowerShell as Administrator in Current Folder

Windows 10 and 11 have largely replaced the 'Open command window here' option with 'Open PowerShell window here'. You can also elevate PowerShell directly from Explorer.

1. Open PowerShell Here (Standard)

Navigate to your desired folder in File Explorer. Hold Shift and right-click on an empty space within the folder. Select Open PowerShell window here.

2. Elevate PowerShell (Manual)

Once the PowerShell window opens, you can type Start-Process powershell -Verb RunAs to open a new, elevated PowerShell window. This will open in a new window, likely in System32, so you'd still need to cd to your original path.

3. Registry Hack for Elevated PowerShell

Similar to the CMD hack, you can modify the registry to add an 'Open PowerShell as Administrator Here' option. Navigate to HKEY_CLASSES_ROOT\Directory\shell\PowerShell (or create a new key if it doesn't exist for your desired entry). Under its command subkey, you can use a command like: powershell.exe -NoExit -Command "Set-Location -LiteralPath '%V'; Start-Process powershell -Verb RunAs -ArgumentList '-NoExit -Command \"Set-Location -LiteralPath \"%V\"\"'"

This is more complex as it tries to launch an elevated PowerShell from within a non-elevated one, passing the path. A simpler approach is to use the runas verb directly on the PowerShell executable.

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runasps]
@="Open PowerShell as Administrator Here"
"Icon"="powershell.exe"
"Extended"=""

[HKEY_CLASSES_ROOT\Directory\shell\runasps\command]
@="powershell.exe -NoExit -Command Set-Location -LiteralPath '%V' -Verb RunAs"

Registry entry to add 'Open PowerShell as Administrator Here' to the context menu (requires Extended for Shift+Right-Click).

Note: The -Verb RunAs argument in the PowerShell command above might not work directly as expected when invoked from the registry in this manner. The most reliable way to get an elevated PowerShell in the current directory is still the runas verb on the parent shell key, similar to the CMD example.