Open Command Window Here as Administrator - Context menu

vbimport

#1

I got a phonecall from a friend who could not get the old context menu choice to work correctly in Windows 10. I told him to search the net but he replied he could not locate anything?!?
O.K. I did help him by expanding the reg-file. Then I went and searched the net myself… While he was not entirely correct, there are information out there covering the topic, but the information is not found in one place (at least I did not find it) and so for all of you, here it is… The one forum thread covering it for Windows 10

There is no doubt about it and it has served its purposet for years…
add_Open_Command_Window_Here_as_Administrator.reg used to be the defacto standard for opening a command prompt as administrator. However, there are a few shortcomings to the entries in Windows 10.


The original is like this: Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@=“Open Command Window Here as Administrator”
“Icon”=“C:\Windows\System32\imageres.dll,-78”

[-HKEY_CLASSES_ROOT\Directory\shell\runas\command]

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

Seemingly good, but only if you do not have UAC active (User Account Control). If you do, this will never bring up an administrative command-prompt. That is, a command window will open, but not as administrator and this is due to a command missing in the original. Another flaw is that it will not work for drives or library folders which is evident since it only is set for “Directory”.

To make it more flexible, I wanted to include the two and add the needed command so it elevates correctly with UAC operational, and as seen below, that is not too hard:

– Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@=“Open command window here as Administrator”
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@=“Open command window here as Administrator”
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[-HKEY_CLASSES_ROOT\Drive\shell\runas]

[HKEY_CLASSES_ROOT\Drive\shell\runas]
@=“Open command window here as Administrator”
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell]
@=“none”

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]
@=“Open command window here as Administrator”
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

As you can see, I added the “HasLUAShield”="" which places the administrator UAC shield with icon to the command. That is all that is needed for the command to work as it should. The above expands the entries from just working when right-clicking “Directory” to work when right-clicking “Drive” and “LibraryFolder” as well :wink:

----------------------------------------------------------- Download:
Here are ready-to-use .reg files for you:


Now, that is it, those who just want the right-click menu choice can stop reading as I will be covering a little extra not needed below:

Another addition to the above would be to only have the shortcut appear when you hold down the [Shift] key while right-clicking to not have it so easily accessible (a possible scenario is if more than one is using the computer)
For that you have to add just one line to the “Directory”, “Drive” and “LibraryFolder” sections. “Extended”="" is the function which takes care of this behavior.
A last addition is if you wish the command to also be selectable if you right-click and empty spot when the directory is open and not only from the icon, this can be implemented by adding “NoWorkingDirectory”="" under “Extended”="" for all three sections.
Do keep in mind that you must [Shift]+right-click even a blank spot in the folder due to the “Extended”="" property

Adding both these and the script would look like this:

– Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@=“Open command window here as Administrator”
“Extended”=""
“NoWorkingDirectory”=""
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
@=“Open command window here as Administrator”
“Extended”=""
“NoWorkingDirectory”=""
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[-HKEY_CLASSES_ROOT\Drive\shell\runas]

[HKEY_CLASSES_ROOT\Drive\shell\runas]
@=“Open command window here as Administrator”
“Extended”=""
“NoWorkingDirectory”=""
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell]
@=“none”

[-HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]
@=“Open command window here as Administrator”
“Extended”=""
“NoWorkingDirectory”=""
“HasLUAShield”=""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas\command]
@=“cmd.exe /s /k pushd “%V””

The above is a good example of how to add both extend and restrict usage at the same time. Personally I don’t use any of the two, but it is a possibility to add both, or just “NoWorkingDirectory”="" to have the shortcut available almost everywhere if you like. I leave it up to you to edit the above downloadable script if you like to add any of the functionality :slight_smile:


Of course, there used to be registry entries to remove or uninstall the choice for reasons unknown :bigsmile:, and that is achieved this registry file (also part of the download): Windows Registry Editor Version 5.00

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[-HKEY_CLASSES_ROOT\Directory\Background\shell\runas]

[-HKEY_CLASSES_ROOT\Drive\shell\runas]

[-HKEY_CLASSES_ROOT\LibraryFolder\background\shell\runas]
Hopefully I have managed to explain it so you understand what is going on. If anything is unclear, please do not hesitate in asking :flower:

>>------------------------------------------------------->>