Windows – More than one ‘Open xxxxx here as Administrator’

cmd.exepowershellrunaswindows

I want the option to open a Command window or Powershell window as Administrator from the drive and directory context menus in Windows.

I can have either by creating and populating the special 'runas' registry keys shown below, but is there a way I can have both listed on the context menu and have both run as Administrator?

[HKEY_CLASSES_ROOT\Drive\shell\runas]
...
[HKEY_CLASSES_ROOT\Drive\shell\runas\command]
...
[HKEY_CLASSES_ROOT\Directory\shell\runas]
...
[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
...
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas]
...
[HKEY_CLASSES_ROOT\Directory\Background\shell\runas\command]
...

Best Answer

Next registry hack works for directories on Windows 8.1:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runas]
"HasLUAShield"=""
@="CMD here as administrator"

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /S /K pushd \"%V\""
"DelegateExecute"=""

[HKEY_CLASSES_ROOT\Directory\shell\runasPowerShell]
"HasLUAShield"=""
@="PowerShell here as administrator"

[HKEY_CLASSES_ROOT\Directory\shell\runasPowerShell\command]
@="Powershell Start-Process PowerShell -verb runas -ArgumentList '-noexit', 'Push-Location -literalPath ''\"%V\"'''"
"DelegateExecute"=""

You could add analogous runas and runasPowerShell subkeys for drives under the [HKEY_CLASSES_ROOT\Drive\shell] as well.

Run both CMD and PowerShell with elevated privileges

Related Question