Runas Elevated Command Promt From Anywhere in Windows 7

Karl Is WrightHacks n Mods, Tutorial, Windows Tips

The Intro

How often have you had to deal with the headache of manually cd C:/Program\Files your way around in windows 7? I love windows, and I use it for my everyday, but if there’s anything windows lacks, it’s a decent command prompt.

Look at the beautiful command prompt that Linux comes with!

[frame_left src=”” href=””] You can do this in windows too!

What’s more, in Linux (Unix) you can use sudo or su to elevate from within the terminal.

Why can’t the windows command prompt be this helpful?

It can. We need to use a ‘workaround’ to do it though.

The Situation

You may not know it, but you can already open a command prompt from any folder you have open in windows 7, Vista & XP (8…?) by holding shift & right-click.

[frame_left src=”” href=””][/frame_left]

However, what if you want to be able to open a command prompt with Administrator privileges? Currently the only way you can do this is by creating a shortcut to the cmd prompt and right-clicking it to be able to run it as admin. Even then, you still have to cd into the directory you want to work in.

How annoying. Let’s fix that.

To change the right-click menu, we need to make some changes to the registry.

The Short

Copy the following text and save it as a file on your desktop, named cmd_admin.reg, right-click it -> Merge.

Windows Registry Editor Version 5.00

;    Created by Karl Wright
;    Tutorial:

[-HKEY_CLASSES_ROOTDirectoryshellrunas] [HKEY_CLASSES_ROOTDirectoryshellrunas] @="@shell32.dll,-8506"

[HKEY_CLASSES_ROOTDirectoryshellrunascommand] @="cmd.exe /s /k pushd "%V""

[-HKEY_CLASSES_ROOTDirectoryBackgroundshellrunas] [HKEY_CLASSES_ROOTDirectoryBackgroundshellrunas] @="@shell32.dll,-8506"

[HKEY_CLASSES_ROOTDirectoryBackgroundshellrunascommand] @="cmd.exe /s /k pushd "%V""

[-HKEY_CLASSES_ROOTDriveshellrunas] [HKEY_CLASSES_ROOTDriveshellrunas] @="@shell32.dll,-8506"

[HKEY_CLASSES_ROOTDriveshellrunascommand] @="cmd.exe /s /k pushd "%V""

The Long

So what does all that code actually do?

The first line: Windows Registry Editor Version 5.00
All registry programs start with this line. It pretty much just tells windows that this a registry program.

Lines that begin with ; are comments, they are solely for the reader and not for the computer at all.

[-HKEY_CLASSES_ROOTDirectoryshellrunas] The first part, -, tells the computer that this entry is to be removed, the rest of the entry tells the computer what entry to remove. Note, here, it is only the, runas, entry that is being removed, top-level directories are left alone.

If – means remove, nothing means to add. So,
[HKEY_CLASSES_ROOTDirectoryshellrunas] means to create a runas entry.

If we look at HKEY_CLASSES_ROOTDirectoryshellcmd we find a couple of entries and a subdirectory called, command, with its own key inside of that.

This is basically the entry that puts the contextual “open command window here” entry into your shift rick-click menu.

So all we need to do, is copy that, which is what I’ve done in my program and make a few minor adjustments to give ourselves administrator access when we open it up.

Default – lists what shell to use
Extended – show on shift right-click

command -> default – the command that we want to run that will tell the terminal to cd into the current directory.

The changes we are going to make;

Instead of a cmd directory, we’re going to use a runas directory, with one other extra key than the cmd directory had.


This key, combined with the runas directory are what tell windows to run this command as an administrator.

The Summation

Hopefully, if all goes well, you should have an additional entry in your shift right-click menu, to open a command window in a directory with administrator rights already secured.

[frame_center src=”” href=””] [/frame_center]

There’s no reason why you can’t use this technique to put all kinds of shortcuts in your menu.

Post your reactions in the comments section below!