1

I found a way how to add a context menu, when I right click in a Windows explorer, to open command line in a current directory.

It is sufficient to create two Windows registry entries:

HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt e.g. with value "Open CMD here..." and HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command with value "cmd.exe /k cd /d %1"

or simple creating a file cmd.reg and executing it:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt]
@="Open CMD here..."

[HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\command]
@="cmd.exe /k cd /d %1"

But how can I achieve the same thing, which will force cmd.exe to "Run as Administrator"?

ethcz
  • 135
  • 2
  • 9

2 Answers2

4

There is however more possible by "hacking" the registry, like losing the need to push shift.. just a right click is enough imo.. and why not have two seperate clear entries ? :-)

Each key with runas is an run as admin-key basically in combination with "HasLUAShield"="" before specifying the same command as when having no elevated rights.

The tweak below will make everything crystal clear.

Windows Registry Editor Version 5.00
; OLDSKOOL-TWEAK : Open command prompt on drives, directories
; version rightclick (no shift needed) :
; for standard "Open command window here"
; and added : "Open command windows here (Admin)"
;
[HKEY_CLASSES_ROOT\Directory\shell\cmd]
@="@shell32.dll,-8506"
"Extended"=-
"NoWorkingDirectory"=""

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

[-HKEY_CLASSES_ROOT\Directory\shell\runas]

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Open command window here (Admin)"
"HasLUAShield"=""

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

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd]
@="@shell32.dll,-8506"
"Extended"=-
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\cmd\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 (Admin)"
"HasLUAShield"="

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

[HKEY_CLASSES_ROOT\Drive\shell\cmd]
@="@shell32.dll,-8506"
"Extended"=-
"NoWorkingDirectory"=""

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

[-HKEY_CLASSES_ROOT\Drive\shell\runas]

[HKEY_CLASSES_ROOT\Drive\shell\runas]
@="Open command window here (Admin)"
"HasLUAShield"=""

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

You don't have to hack your registry. Just use shift right click. Also, I believe that menu gives you a command prompt as admin option. If not, just create a registry for a cmd shortcut that starts in system32. That's basically the admin command prompt