X Tutup
The Wayback Machine - https://web.archive.org/web/20240916121456/https://github.com/PowerShell/PowerShell/issues/23997
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell v7 (as well as Windows PowerShell) right-click context menu entries don't work on libraries. #23997

Open
5 tasks done
Bamajon1974 opened this issue Jun 29, 2024 · 1 comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.

Comments

@Bamajon1974
Copy link

Prerequisites

Steps to reproduce

PowerShell v7 installs right-click context menu entries to launch a PowerShell window when right clicking a directory, directory background, or drive. The entries are installed in HKCU\Directory\shell, HKCU\Directory\Background\Shell and HKCU\Drive. These entries work fine....meaning that when selecting Open PowerShell 7 window upon right-clicking a directory, directory background or drive, a PowerShell window opens up to the desired directory.

However, PowerShell also installs right click context menu entries for Libraries that do not work. PowerShell entries are not installed at HKCU\Library\Background\Shell, but, when right clicking the main library icon in File Explorer Navigation Pane, or the background of the main library virtual folder, a PowerShell context menu entry appears. When PowerShell is launched from the entry in a library, nothing happens. Note that, the PowerShell right-click entries for individual libraries, such as documents or pictures, have no PowerShell entries unless added to HKCR\Library\Background\shell
So, I would like to either: modify the context menu commands for PowerShell to open in libraries (which I don't think is possible for virtual folders) or exclude libraries, but not regular folders, from the registry entries.

How do I do this?

After looking into the issue further....the default PowerShell and Command Prompt context menu entries included in Win10 also do not open in libraries. See attached pic for the error message when launching PowerShell from right-click menu in libraries. Would this question be better directed to Microsoft?

Expected behavior

PowerShell v7 installs right-click context menu entries to launch a PowerShell window when right clicking a directory, directory background, or drive. The entries are installed in HKCU\Directory\shell, HKCU\Directory\Background\Shell and HKCU\Drive. These entries work fine....meaning that when selecting Open PowerShell 7 window upon right-clicking a directory, directory background or drive, a PowerShell window opens up to the desired directory.

Actual behavior

However, PowerShell also installs right click context menu entries for Libraries that do not work. PowerShell entries are not installed at HKCU\Library\Background\Shell, but, when right clicking the main library icon in File Explorer Navigation Pane, or the background of the main library virtual folder, a PowerShell context menu entry appears. When PowerShell is launched from the entry in a library, nothing happens. Note that, the PowerShell right-click entries for individual libraries, such as documents or pictures, have no PowerShell entries unless added to HKCR\Library\Background\shell
So, I would like to either: modify the context menu commands for PowerShell to open in libraries (which I don't think is possible for virtual folders) or exclude libraries, but not regular folders, from the registry entries.

How do I do this?

After looking into the issue further....the default PowerShell and Command Prompt context menu entries included in Win10 also do not open in libraries. See attached pic for the error message when launching PowerShell from right-click menu in libraries. Would this question be better directed to Microsoft?

Error details

No response

Environment data

PowerShell V7

Visuals

PowerShell1 PowerShell2 PowerShell3
@Bamajon1974 Bamajon1974 added the Needs-Triage The issue is new and needs to be triaged by a work group. label Jun 29, 2024
@mklement0
Copy link
Contributor

First, let me provide some context:

  • Libraries are collections of folders, so it doesn't make sense to offer an "Open here" shortcut-menu command on them, as there'd be no single folder to navigate to (in File Explorer, a virtual view spanning multiple folders can be presented, but there's no console (terminal) equivalent).

  • Libraries were introduced in Windows 7, but it seems that they've been de-emphasized starting with Windows 10: they're hidden by default now.

  • In Windows 11, in general, File Explorer shortcut (context) menus present a simplified view; in order to see all available shortcut commands, you either need to hold down Shift while right-clicking, or select the Show more options in the menu that shows after a regular right click.


Note: The Windows 11 (W11) statements below are based on the 22H2 version I'm running.

The fact that the PowerShell MSI installer defines a HKEY_CLASSES_ROOT\LibraryFolder\background\shell entry - note the background part - means that the commands defined this way are not meant to be available at the level of individual libraries; as argued above, this wouldn't make sense.

Instead, this entry relates to right-clicking on the background of the virtual Libraries folder view.

The limited utility this hypothetically provides - opening a PowerShell terminal in $env:APPDATA\Microsoft\Windows\Libraries - is thwarted in practice: on W11 (22H2), the operation is a quiet no-op, for reasons unknown to me - this does sound like a Windows bug.

PowerShell uses a central definition in HKEY_CLASSES_ROOT\Directory\ContextMenus\shell for all of the following: drives, regular folders (and their backgrounds), the desktop background, and the library background, which is based on passing the target directory via %V.


Things are different in the tree view (left sidebar):

  • First, in Windows 10, if memory serves, but definitely in Windows 11, you must explicitly enable showing libraries in the tree, by right-clicking on the background and selecting Show libraries.

  • Once you've done so, it seem that it is again Windows bugs that surface:

    • The Libraries node itself, is arguably a regular folder - namely $env:APPDATA\Microsoft\Windows\Libraries - but neither PowerShell's nor other application's commands seem to work on it (quiet no-op in W11; per your screenshot, an error in W10).
  • By design, the PowerShell commands should not be offered on the individual library nodes (just like they aren't offered on the icons representing the individual libraries in the folder view):

    • In W10, per your screenshots, they commendably aren't.
    • In W11, unfortunately, they are, and - again - they do not work.
    • (By contrast, at least in W11, they are and should be offered on the individual folders that make up a given library, on which the PowerShell commands do work.)

A mitigation of the problem is to make the MSI installer not write an HKEY_CLASSES_ROOT\LibraryFolder\background\shell entry:

  • This wouldn't be much of an improvement on W10, except to not present the - presumably non-functional - PowerShell commands when right-clicking the background of the folder view.

  • On W11, additionally, it would remove the non-functional - and conceptually pointless - PowerShell commands from the individual library nodes in the tree view.

The bug with respecting to right-clicking the Libraries node itself in the tree view would persist, however.


As an aside:

  • The MSI installer also offers an Add 'Run with PowerShell 7' context menu for PowerShell option, to allow running individual .ps1 files directly from File Explorer.

    • As a (nested) aside: If this option did work (see next point), it would be hampered by invoking the script without the -NoExit CLI switch, meaning that scripts will by default automatically exit the session and thereby close their console window - the same applies to the analogous command that Windows PowerShell defines.
  • However, on my W11 (22H2) machine, this command never shows - for reasons unknown to me.

    • As a(nother) (nested) aside: The intended - but ineffective - command is problematic in itself:

      • C:\Program Files\PowerShell\7\pwsh.exe -Command "$host.UI.RawUI.WindowTitle = 'PowerShell 7 (x64)'; & '%1'"
      • First, the lack of quoting around the pwsh.exe path - despite its containing spaces - is conceptually problematic, though - surprisingly - in itself that is not a problem.
      • '...' quoting around %1 isn't robust, given that ' is a legal file-name character.
      • Thus, the command line should be:
        • "C:\Program Files\PowerShell\7\pwsh.exe" -Command "$host.UI.RawUI.WindowTitle = 'PowerShell 7 (x64)'; & \"%1\""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Triage The issue is new and needs to be triaged by a work group.
Projects
None yet
Development

No branches or pull requests

2 participants
X Tutup