Skip to content

Instantly share code, notes, and snippets.

@davecan
Last active July 7, 2024 22:08
Show Gist options
  • Save davecan/f3045266aa9e3441211ab55f9db70c2b to your computer and use it in GitHub Desktop.
Save davecan/f3045266aa9e3441211ab55f9db70c2b to your computer and use it in GitHub Desktop.
How to enable "Open PowerShell Here" context menu in Windows 10

After checking multiple tutorials I had to take pieces from each of the following to get this to work on my Win10 system:

Basically it uses the steps from the first article, but under the background path from the second article. Neither article on its own worked for me.

Steps:

  1. Open regedit and go to path HKEY_CLASSES_ROOT\Directory\background\shell.

  2. Create new key powershellmenu.

  3. Change the Default value of the powershellmenu key to Open in PowerShell. (or whatever)

  4. Create new key command under powershellmenu.

  5. Change the Default value of the command key to:

    C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command Set-Location -LiteralPath '%L'

  6. Right-click on powershellmenu key and select Permissions, then set permissions to Full control for the Administrators group. (or whatever group/user)

Then try right-clicking in some folder and it should work.

@SingusTheTexan
Copy link

i changed it to "%v" and it does not work.

@LtqxWYEG
Copy link

LtqxWYEG commented Nov 17, 2023

Don't know what to tell you. Update your software, maybe? Or did you forget the "/", slashs?
I'm using windows 10 pro. Newest everything, afaik. Shouldn't have any effect on this, though.

@SingusTheTexan
Copy link

ok i do have to update then

@LtqxWYEG
Copy link

LtqxWYEG commented May 3, 2024

Ugh. Something broke and I had make all commands again...

Here are the regs for when you use

WINDOWS TERMINAL and POWERSHELL 7 (pwsh.exe) , and NOTEPAD++ because "edit" entries.

Features:

  • Open command prompt here, /as administrator
  • Run as user / Run as admininstrator
  • Edit with Notepad++ instead
  • Correct icons used. (Apart from edit)
Windows Registry Editor Version 5.00

; Start registry entries for "Open a cmd cli" here

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
[HKEY_CLASSES_ROOT\Drive\background\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Drive\background\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
[HKEY_CLASSES_ROOT\LibraryFolder\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\LibraryFolder\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedCmd]
@="Open command prompt here as administrator"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedCmd\command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""

; End registry entries for "Open a cmd cli" here


;  Now non-elevated "open cli here" and context menu entries like: Run as administrator, Run, Edit ... bleh bleh bleh (Hex is for elevated)

[HKEY_CLASSES_ROOT\Directory\shell\cmd\]
@="Open command prompt here"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\shell\cmd\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /k cd \\`\\\"%V\\`\\\"\\\"\""
[HKEY_CLASSES_ROOT\Directory\background\shell\cmd]
@="Open command prompt here"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Directory\background\shell\cmd\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /k cd \\`\\\"%V\\`\\\"\\\"\""
[HKEY_CLASSES_ROOT\Drive\shell\cmd\]
@="Open command prompt here"
"Icon"="cmd.exe"
[HKEY_CLASSES_ROOT\Drive\shell\cmd\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /k cd \\`\\\"%V\\`\\\"\\\"\""
[HKEY_CLASSES_ROOT\cmdfile\shell\open\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /c \\\"%1\\\" %*\""
[HKEY_CLASSES_ROOT\cmdfile\shell\runas\command]
@=hex(2):70,00,77,00,73,00,68,00,2e,00,65,00,78,00,65,00,20,00,2d,00,63,00,6f,\
  00,6d,00,6d,00,61,00,6e,00,64,00,20,00,22,00,53,00,74,00,61,00,72,00,74,00,\
  2d,00,50,00,72,00,6f,00,63,00,65,00,73,00,73,00,20,00,2d,00,56,00,65,00,72,\
  00,62,00,20,00,52,00,75,00,6e,00,41,00,73,00,20,00,77,00,74,00,2e,00,65,00,\
  78,00,65,00,20,00,5c,00,22,00,63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,20,\
  00,2f,00,63,00,20,00,5c,00,60,00,5c,00,22,00,25,00,56,00,5c,00,60,00,5c,00,\
  22,00,20,00,25,00,25,00,2a,00,5c,00,22,00,22,00,00,00
[HKEY_CLASSES_ROOT\batfile\shell\open\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /c \\\"%1\\\" %*\""
[HKEY_CLASSES_ROOT\batfile\shell\runas\command]
@=hex(2):70,00,77,00,73,00,68,00,2e,00,65,00,78,00,65,00,20,00,2d,00,63,00,6f,\
  00,6d,00,6d,00,61,00,6e,00,64,00,20,00,22,00,53,00,74,00,61,00,72,00,74,00,\
  2d,00,50,00,72,00,6f,00,63,00,65,00,73,00,73,00,20,00,2d,00,56,00,65,00,72,\
  00,62,00,20,00,52,00,75,00,6e,00,41,00,73,00,20,00,77,00,74,00,2e,00,65,00,\
  78,00,65,00,20,00,5c,00,22,00,63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,20,\
  00,2f,00,63,00,20,00,5c,00,60,00,5c,00,22,00,25,00,56,00,5c,00,60,00,5c,00,\
  22,00,20,00,25,00,25,00,2a,00,5c,00,22,00,22,00,00,00
[HKEY_CLASSES_ROOT\batfile\shell\edit\command]
@=hex(2):43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,00,46,\
  00,69,00,6c,00,65,00,73,00,5c,00,4e,00,6f,00,74,00,65,00,70,00,61,00,64,00,\
  2b,00,2b,00,5c,00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,2b,00,2e,\
  00,65,00,78,00,65,00,20,00,25,00,31,00,00,00
[HKEY_CLASSES_ROOT\cmdfile\shell\edit\command]
@=hex(2):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
  00,46,00,69,00,6c,00,65,00,73,00,5c,00,4e,00,6f,00,74,00,65,00,70,00,61,00,\
  64,00,2b,00,2b,00,5c,00,6e,00,6f,00,74,00,65,00,70,00,61,00,64,00,2b,00,2b,\
  00,2e,00,65,00,78,00,65,00,22,00,20,00,25,00,31,00,00,00

And the same for for PowerShell 7...

Windows Registry Editor Version 5.00

; Start registry entries for "Open a powershell 7 cli" here

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""
[HKEY_CLASSES_ROOT\Drive\background\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\Drive\background\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""
[HKEY_CLASSES_ROOT\LibraryFolder\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\LibraryFolder\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS]
@="Open PowerShell 7 here as administrator"
"Icon"="pwsh.exe"
"HasLUAShield"=""
[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS\command]
@="pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

; End registry entries for "Open a powershell 7 cli" here

;  Now  non-elevated "open pwsh here" and context menu entries like: Run as administrator, Run, Edit ... bleh bleh bleh (Hex is for elevated)

Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\.ps1\DefaultIcon]
@="C:\\Program Files\\PowerShell\\7\\pwsh.exe"
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\DefaultIcon]
@="C:\\Program Files\\PowerShell\\7\\pwsh.exe"
[HKEY_CLASSES_ROOT\Drive\shell\Powershell\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" pwsh.exe -NoExit -Command Set-Location -LiteralPath \"%V\""
[HKEY_CLASSES_ROOT\Directory\shell\Powershell\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" pwsh.exe -NoExit -Command Set-Location -LiteralPath \"%V\""
[HKEY_CLASSES_ROOT\Directory\background\shell\Powershell\command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" pwsh.exe -NoExit -Command Set-Location -LiteralPath \"%V\""
[HKEY_CLASSES_ROOT\.ps1\Shell\Open\Command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"pwsh.exe -command \\\"%1\\\" %*\""
[HKEY_CLASSES_ROOT\.ps1\Shell\runas\Command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -command `\\\"%1`\\\" %%*\\\"\""
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\Open\Command]
@="\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"pwsh.exe -Command \\\"%1\\\" %*\""
[HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\Shell\runas\Command]
@="pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -command `\\\"%1`\\\" %%*\\\"\""
[HKEY_CLASSES_ROOT\SystemFileAssociations\.ps1\Shell\Edit\Command]
@="\"C:\\Program Files\\Notepad++\\notepad++.exe\" \"%1\""

Again: WINDOWS TERMINAL and POWERSHELL 7 (pwsh.exe) and NOTEPAD++ needed

Edit: Mah, here all commands both as working command and formatted for registry files

# TODO or TOOWN:
# -------------
# HKEY_CLASSES_ROOT\Directory\shell\Powershell\command  protected
# HKEY_CLASSES_ROOT\Drive\shell\Powershell\command      protected
#
# For use with WINDOWS TERMINAL, POWERSHELL 7 only


# ------------- Collection of all commands for "open something" or "run something" ------------

# ---------------------------------------
#              RUN SCRIPT
Filetype: .bat, cmd
Command: "C:\Users\Distelzombie\AppData\Local\Microsoft\WindowsApps\wt.exe" "cmd.exe /c \"%1\" %*"
Formatted: "\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /c \\\"%1\\\" %*\""
# ---
Filetype: .ps1
Command: "C:\Users\Distelzombie\AppData\Local\Microsoft\WindowsApps\wt.exe" "pwsh.exe -command \"%1\" %*"
Formatted: "\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"pwsh.exe -command \\\"%1\\\" %*\""

# ---------------------------------------
#         RUN SCRIPT --ELEVATED--
Filetype: .bat, cmd
Command: pwsh.exe -command "Start-Process -Verb RunAs wt.exe \"cmd.exe /c \`\"%1\`\" %%*\""
Formatted: @=hex(2):70,00,77,00,73,00,68,00,2e,00,65,00,78,00,65,00,20,00,2d,00,63,00,6f,\
  00,6d,00,6d,00,61,00,6e,00,64,00,20,00,22,00,53,00,74,00,61,00,72,00,74,00,\
  2d,00,50,00,72,00,6f,00,63,00,65,00,73,00,73,00,20,00,2d,00,56,00,65,00,72,\
  00,62,00,20,00,52,00,75,00,6e,00,41,00,73,00,20,00,77,00,74,00,2e,00,65,00,\
  78,00,65,00,20,00,5c,00,22,00,63,00,6d,00,64,00,2e,00,65,00,78,00,65,00,20,\
  00,2f,00,63,00,20,00,5c,00,60,00,5c,00,22,00,25,00,31,00,5c,00,60,00,5c,00,\
  22,00,20,00,25,00,25,00,2a,00,5c,00,22,00,22,00,00,00
# ---
Filetype: .ps1
Command: pwsh.exe -command "Start-Process -Verb RunAs wt.exe \"pwsh.exe -command `\"%1`\" %%*\""
Formatted: "pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -command `\\\"%1`\\\" %%*\\\"\""

# ---------------------------------------
# OPEN NEW CLI, WITH WORKING-DIRECTORY SET FROM CONTEXT. (CLI = Command Line Interface)
Filetype: .bat, cmd
Command: "C:\Users\Distelzombie\AppData\Local\Microsoft\WindowsApps\wt.exe" cmd.exe /k cd "%V"
Formatted: "\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" \"cmd.exe /k cd \\`\\\"%V\\`\\\"\\\"\""
# ---
Filetype: .ps1
Command: "C:\Users\Distelzombie\AppData\Local\Microsoft\WindowsApps\wt.exe" pwsh.exe -NoExit -Command Set-Location -LiteralPath "%V"
Formatted: "\"C:\\Users\\Distelzombie\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe\" pwsh.exe -NoExit -Command Set-Location -LiteralPath \"%V\""

# ---------------------------------------
# OPEN NEW --ELEVATED-- CLI, WITH WORKING-DIRECTORY SET FROM CONTEXT. (CLI = Command Line Interface)
Filetype: .bat, .cmd
Command: pwsh.exe -command "Start-Process -Verb RunAs wt.exe \"cmd.exe /k cd \`\"%V\`\"\""
Formatted:  "pwsh.exe -command \"Start-Process -Verb RunAs wt.exe \\\"cmd.exe /k cd \\\`\\\"%V\\\`\\\"\\\""
# ---
Filetype: .ps1
Command: pwsh.exe -Command "Start-Process -Verb RunAs wt.exe \"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\""
Formatted: "pwsh.exe -Command \"Start-Process -Verb RunAs wt.exe \\\"pwsh.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment