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.

@h8rt3rmin8r
Copy link

A helpful powershell script (pillaged from superuser) to accomplish the same thing:

'Directory',
'Directory\Background',
'Drive' | ForEach-Object {
  $Path = "Registry::HKEY_CLASSES_ROOT\$_\shell\PowerShellHere";
  New-Item -Path $Path -Name 'command' -Force | Out-Null;
  Set-ItemProperty -Path "$Path\command" -Name '(default)' -Value 'PowerShell -NoExit -NoLogo -Command Set-Location "%V"';
  Set-ItemProperty -Path $Path -Name '(default)' -Value 'PowerShell';
  Set-ItemProperty -Path $Path -Name 'Icon' -Value "${Env:WinDir}\System32\WindowsPowerShell\v1.0\powershell.exe,0";
}

(remember to run as admin)

This is great, but it's opening PowerShell 5 instead of the new PowerShell 7, can anyone guide me on what to change in the reg key so it opens ProgramFiles\PowerShell\7\pwsh.exe instead of System32\WindowsPowerShell\v1.0\powershell.exe? The only path I found in the instructions above is for the icon.

I'm currently building a solution to this very thing. I'll try to remember to share when I'm done. It's crazy how much inaccurate information is out there on this topic lol

@h8rt3rmin8r
Copy link

Just tested and the following script is working flawlessly for setting up right-click and SHIFT + right-click menus on both directories and attached storage devices for PowerShell 7:

#!/usr/bin/env pwsh
#------------------------------------------------------------------------------
#
# [ regedit-open-ps-here.ps1 ]
#
# Description:
#
#    A PowerShell script that will loop over the following registry entries:
#
#    HKEY_CLASSES_ROOT\Directory\ (right-click menu on directories)
#    HKEY_CLASSES_ROOT\Directory\Background (SHIFT + right-click menu on directories)
#    HKEY_CLASSES_ROOT\Drive (right-click menu on attached storage devices)
#
#    ... and create new items that add an option to "Open PowerShell 7 Here"
#
#    NOTE: This script must be run as "Administrator" (because we're editing
#    the Windows Registry)
#
#    NOTE: This script sets up a right-click menu option for PowerShell 7, not
#    the older built-in version of PowerShell!
#
# Reference:
#
#    # Github Gist by davecan (and related comments)
#    http://bit.ly/3GYmlbO
#
#    # My comment on the above-referenced Github Gist
#    http://bit.ly/3H3zu3n
#
#    # How to Check If a PowerShell Script Is Run As Administrator
#    http://bit.ly/3R8PRAq
#
#------------------------------------------------------------------------------

Write-Host "Checking for elevated permissions..."

if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
	
    Write-Warning "Insufficient permissions to run this script."
	Write-Host "Open the PowerShell console as an administrator and run this script again."
	
    Break

} else {
	Write-Host "Success: Code is running as administrator." -ForegroundColor Green
    Write-Host "Beginning edits to the Windows Registry ..."
    
    'Directory',
    'Directory\Background',
    'Drive' | ForEach-Object {
      $Path = "Registry::HKEY_CLASSES_ROOT\$_\shell\PowerShellMenu";
      New-Item -Path $Path -Name 'command' -Force | Out-Null;
      Set-ItemProperty -Path "$Path\command" -Name '(default)' -Value '"C:\Program Files\PowerShell\7\pwsh.exe" -NoExit -Command Set-Location -LiteralPath "%V"';
      Set-ItemProperty -Path $Path -Name '(default)' -Value 'Open PowerShell 7 Here';
      Set-ItemProperty -Path $Path -Name 'Icon' -Value "C:\Program Files\PowerShell\7\pwsh.exe,0";
    }
    
    Write-Host "Operations complete"
}

@FCalleja - I hope this helps ;-)

@Weldryn
Copy link

Weldryn commented Feb 21, 2023

A helpful powershell script (pillaged from superuser) to accomplish the same thing:

'Directory',
'Directory\Background',
'Drive' | ForEach-Object {
  $Path = "Registry::HKEY_CLASSES_ROOT\$_\shell\PowerShellHere";
  New-Item -Path $Path -Name 'command' -Force | Out-Null;
  Set-ItemProperty -Path "$Path\command" -Name '(default)' -Value 'PowerShell -NoExit -NoLogo -Command Set-Location "%V"';
  Set-ItemProperty -Path $Path -Name '(default)' -Value 'PowerShell';
  Set-ItemProperty -Path $Path -Name 'Icon' -Value "${Env:WinDir}\System32\WindowsPowerShell\v1.0\powershell.exe,0";
}

(remember to run as admin)

This is great, but it's opening PowerShell 5 instead of the new PowerShell 7, can anyone guide me on what to change in the reg key so it opens ProgramFiles\PowerShell\7\pwsh.exe instead of System32\WindowsPowerShell\v1.0\powershell.exe? The only path I found in the instructions above is for the icon.

Use pwsh instead of ${Env:WinDir}\System32\WindowsPowerShell\v1.0\powershell.exe and Powershell 7 will be launched instead. Works for me

@tech-bash
Copy link

Mine also worked with '%V'.

@d3NNEb
Copy link

d3NNEb commented Mar 22, 2023

shift + right-click on folder works

@Lunar808
Copy link

@davecan You saved me man
I did create in the past this key, but it didn't work and I pretty much gave up(thanks microsoft)
but my mistake was that I created this key under /shell/ and not /Background/shell

Thanks man

@iubaidrmn
Copy link

I followed this.
https://www.youtube.com/watch?v=RzNiD4WQQ1M

solved my issue

@LtqxWYEG
Copy link

LtqxWYEG commented Jul 8, 2023

I found this page via Google. This is one of the first search results.
So... I wanted to start PS as administrator instead. I tried for an hour and ended up with this:

PowerShell -Command "Start-Process powershell -Verb runAs -ArgumentList '-NoExit', '-Command', 'Set-Location -LiteralPath \"%V\"'"

Here's a registry file for everyone. It adds the context entry everywhere. It adds the icon as well.
(Originally from WinaeroTweaker - but I didn't like that powershell was running "inside" CMD.exe)

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process powershell -Verb runAs -ArgumentList '-NoExit', '-Command', 'Set-Location -LiteralPath \\\"%V\\\"'\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process powershell -Verb runAs -ArgumentList '-NoExit', '-Command', 'Set-Location -LiteralPath \\\"%V\\\"'\""

[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process powershell -Verb runAs -ArgumentList '-NoExit', '-Command', 'Set-Location -LiteralPath \\\"%V\\\"'\""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process powershell -Verb runAs -ArgumentList '-NoExit', '-Command', 'Set-Location -LiteralPath \\\"%V\\\"'\""

And here is the version using Windows Terminal:

PowerShell -Command "Start-Process -Verb RunAs wt.exe \"powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'\""
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process -Verb RunAs wt.exe \\\"powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Directory\Background\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process -Verb RunAs wt.exe \\\"powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\Drive\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process -Verb RunAs wt.exe \\\"powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS]
@="Open PowerShell here as administrator"
"Icon"="powershell.exe"
"HasLUAShield"=""

[HKEY_CLASSES_ROOT\LibraryFolder\background\shell\OpenElevatedPS\command]
@="PowerShell -Command \"Start-Process -Verb RunAs wt.exe \\\"powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'\\\"\""

@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