New
#90
Good morning. Does anyone know how to modify the default non-elevated shift+right-click Open PowerShell Window for directories and drives (in HKCR\directory\Shell\Powershell and HKCR\drive\shell\Powershell) to NOT show up when shift+right clicking Libraries? For example, if one shift+right clicks the Library icon in the explorer navigation pane and tries to open Powershell, an error message pops up because the console cannot open a hard link. I think that an AppliesTo Not string and keyword is the way to modify the relevant registry keys but I am not sure how to implement.
I have asked this question in the past with no solution so I thought I would ask on this thread since it has received some attention this past week.
Thanks!
Those are not the entries that affect the Libraries folder. It's the ones underbackground
.
Unfortunately, any entries underbackground
will show up for Libraries when you right right-click (or shift-right-click when the entry includesExtended
) and there does not appear to be any way to change that.
I don't think I've ever right-clicked or shift-right-clicked Libraries before, so I've never noticed this.
Sorry for the delay in my reply. Holidays kept me busy.
To demonstrate, please open File Explorer, shift+right-click on the Libraries Icon in the Navigation Pane, and click on the "Open PowerShell window here" option. An error message pops up about the file/action not having an associated app. The same thing happens if you shift+right-click on the window background in the main library window (the window that shows pictures, documents, videos, music, etc. libraries). This effect is from the native shift+right-click PowerShell/CMD windows baked into windows.
If you go to HKCR\librarybackground\shell registry key, there is nothing present by default. Apparently, the "open powershell window here" right-click menu entry appears in the library folder because it is present in the HKCR\directory and HKCR\directory keys.
If you examine at @Brink 's take ownership context menu (Add Take Ownership to Context Menu in Windows 10), key directories/drives are excluded by adding AppliesTo NOT strings. I am guessing that it may be possible to resolve the context menu entries with powershell/cmd in libraries by including a similar string in the HKCR\directory key and target libraries but I am not sure how point the string to hard links. Any ideas?
Thanks!
No need to demonstrate. I see the same error. I just said that I hadn't ever noticed that in the past because I never tried to do that before. Since library folders are a combined view of one or more folders, there is no corresponding real path to open. It's easily confused because, to begin with, there is only one folder associated with each library.
Yes, specifically the "background" subkey:Apparently, the "open powershell window here" right-click menu entry appears in the library folder because it is present in the HKCR\directory and HKCR\directory keys.
[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell]
@="@shell32.dll,-8508"
"Extended"=""
"NoWorkingDirectory"=""
"ShowBasedOnVelocityId"=dword:00639bc8
[HKEY_CLASSES_ROOT\Directory\Background\shell\Powershell\command]
@="powershell.exe -noexit -command Set-Location -literalPath '%V'"
And, keep in mind, HKCR is a virtual view that combines the classes entries from HKLM and HKCU. The real location is here:
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Powershell]
@="@shell32.dll,-8508"
"Extended"=""
"NoWorkingDirectory"=""
"ShowBasedOnVelocityId"=dword:00639bc8
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\background\shell\Powershell\command]
@="powershell.exe -noexit -command Set-Location -literalPath '%V'"
TheIf you examine at @Brink 's take ownership context menu (Add Take Ownership to Context Menu in Windows 10), key directories/drives are excluded by adding AppliesTo NOT strings.AppliesTo
option accepts actual paths. Libraries are not real paths, so I can't see any way to exclude them.
TheAppliesTo
option accepts actual paths. Libraries are not real paths, so I can't see any way to exclude them.[/QUOTE]
Ugh, that's what I thought. Thank you for the clarification. An odd but not unexpected oversite by MS.
Another question about the default shift+right-click "open powershell window here" option. I would prefer to disable the default right-click menu entries altogether. The context menu entries can be disabled by adding a "LegacyDisable" or "ProgrammaticAccessOnly" string to the appropriate [HKLM\software\classes\directory\shell\powershell] and analogous background keys. However, an unexpected side effect of disabling the default keys is greying out the powershell menu entries in File Explorer. So if you disable either the directory or background directory (forget which one) right-click entry, the Powershell and AdminPowershell entries in File Explorer (File > Open Windows PowerShell) are also greyed out.
I am guessing that somehow the right-click menu entry for powershell is connected to the ribbon commands. Would you know how to resolve this issue?
Thanks!
Add "LegacyDisable" or "ProgrammaticAccessOnly" (makes no difference) as a string value to the directory\background\shell PowerShell entry only. That will eliminate the PowerShell option from shift-right-click on the background and Libraries, but retain the PowerShell options in Explorer where applicable.
Yes, your code works fine with Unicode paths with the addition of a CHCP command:
The pipe takes some time, causing the Cmd window to be visible noticeably longer than the Reg method, but I thought it would be a good idea to document this anyhow.Code:cmd /c chcp 65001 & echo "%V%" | powershell $Path = $Input.Trim() -replace '''',''''''; Start-Process powershell -ArgumentList $('-NoExit -Command "Set-Location -LiteralPath ''' + $Path + '''"') -Verb RunAs
Both this method and the Reg method will trip on a folder name that contains an environment variable, such as%OS%
, but I think it's safe to say that would be extremely rare.