1

How to have both "Open window command here" and "Open window command here as admin" in the Explorer context menu?

Important notes/details:

Basj
  • 2,143

1 Answers1

1
  • "Open window command here" is hidden by default in Win10, so you can start regedit.exe as TrustedInstaller with the third party freeware tool AdvancedRun, and go in

    HKEY_CLASSES_ROOT\Directory\background\shell\cmd
    

    Rename HideBasedOnVelocityId to HideBasedOnVelocityId_Old and Extended to Extended_Old.

  • An alternative to doing this is to create a totally new key

    Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd2
    

    with Default = "Open cmd here"

    and

    Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd2\command
    

    with Default = cmd.exe /s /k pushd "%V"

  • To have an elevated "Open window command here as admin", create

    Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd3
    

    with Default = "Open cmd here as admin"

    and

    Computer\HKEY_CLASSES_ROOT\Directory\background\shell\cmd3\command
    

    with Default = "C:\Python311\pythonw.exe" "C:\path\to\main.py" "%V"

    and main.py being:

    import os, sys, ctypes
    path = sys.argv[1]
    ctypes.windll.shell32.ShellExecuteW(None, "runas", "cmd.exe", f'/s /k pushd "{path}"', None, 1)
    

    (the elevate-launcher is here Python 3.11)

  • An alternative is using How do I change "Open with Powershell" to "Open with Command Prompt" when shift-rightclicking in Explorer? (see main answer), but this requires to have context menu submenus (to be able to use multiple specific runas shell registry subkey)

Basj
  • 2,143