Question Exclude libraries from custom right-click menu using AppliesTo string

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
I am trying to add custom entries to the Windows 10 File Explorer (x64, v20H2). Specifically, I want to be able to right-click a directory and directory background for command prompt and powershell options to show up. I know I add the corresponding entries to HKCR\Directory\shell and HKCR\Directory\Background\shell keys. Problem is, the command prompt and powershell entries also show up when right clicking libraries and library folders and the command prompts do not work in these virtual folders, from what I have observed.

I believe the best solution, after reading, is to exclude the main library folder and background using an AppliesTo string with a NOT value and some sort of system item path display value and the path to the libraries in the HKCR\Directory\Background\shell subkey but this removes the option for the command prompt and powershell to show up on all directory backgrounds.

How can I fix this? What is the proper use of AppliesTo and AppliesTo NOT? What are the correct variable names in calling out virtual folders/hard links such as libraries? What are the correct paths to libraries?
Thanks!
 
as far as your cmd/powershell in libraries goes, it should work fine for those folders when folder names have english names, if u have localized windows then it may have issues
it can be resolved with mklink /j (creating english folders linked to your localized folders)

as for registry
you can use the standard DOS wildcards in the AppliesTo test (e.g. "?" for exactly 1 character, "*" for 0 or more characters). You can use a variety of operators against the name... such as equal, not equal, contains, starts with, ends with, etc. You can string together multiple conditions with "AND" or "OR" keywords (or use "NOT")
 

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
as far as your cmd/powershell in libraries goes, it should work fine for those folders when folder names have english names, if u have localized windows then it may have issues
it can be resolved with mklink /j (creating english folders linked to your localized folders)

as for registry
you can use the standard DOS wildcards in the AppliesTo test (e.g. "?" for exactly 1 character, "*" for 0 or more characters). You can use a variety of operators against the name... such as equal, not equal, contains, starts with, ends with, etc. You can string together multiple conditions with "AND" or "OR" keywords (or use "NOT")
Thank you for your reply. Is there a way to directly upload images so I can better show what I want to do?

Say I add a command prompt right-click context menu to open a command prompt when I right click a folder or right-click the background of a folder. I add the appropriate verbiage to the following keys:

HKCR\Directory\Shell\CommandPrompt\etc
HKCR\Directory\Background\Shell\CommandPrompt\etc
HKCR\DesktopBackground\CommandPromt\etc (if necessary)
HKCR\LibraryFolder\Background\Shell\CommandPrompt\etc (if necessary)

Command prompt shows up when you right click the main library and individual libraries (music, documents, etc) in the navigation pane as well as clicking the background of the main library and individual libraries. The command prompt only works correctly for the last situation (background of individual libraries) and that is only where I want the right-click entry to show up.

Which key's above do I need to add the command prompt registry verbiage too, which keys need the AppliesTo NOT string/value and what is the correct syntax of the value in this case?

Thanks!
 

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
as far as your cmd/powershell in libraries goes, it should work fine for those folders when folder names have english names, if u have localized windows then it may have issues
it can be resolved with mklink /j (creating english folders linked to your localized folders)

as for registry
you can use the standard DOS wildcards in the AppliesTo test (e.g. "?" for exactly 1 character, "*" for 0 or more characters). You can use a variety of operators against the name... such as equal, not equal, contains, starts with, ends with, etc. You can string together multiple conditions with "AND" or "OR" keywords (or use "NOT")
Did you see my reply? What is the specific syntax to exclude libraries altogether from a right-click option?
 
first thing first...

"appliesto" pretty much works for file types
so u can exclude small files like this:
"AppliesTo"="NOT System.Size:1..4kB"
this will skip context menu on files smaller than 4kB

so what u tryin to do with apllies to wont work

next...
your cmd command is probably wrong thats why it does not work with virtual folders
CMD.exe "%1" is not correct, "cmd.exe \"%V\"" would be correct alongside any other commands u want

next...
windows has this feature already to open CMD or Powershell in any folder/background/drive context menu which is what u tryin to replicate here
it gets activate if you hold shift key and then right click on folder or empty space inside folder, ull get two options there, open command window here/open powershell window here

if u dont want to hold shift key to get that "feature" in context menu
open regedit
HKCR\Drive\Shell\cmd
HKCR\Directory\Shell\cmd
HKCR\Directory\Background\Shell\cmd
HKCR\Drive\Shell\Powershell
HKCR\Directory\Shell\Powershell
HKCR\Directory\Background\Shell\Powershell
delete "Extended" in all these (thats teh shift key context menu) and it will appear in context menu without shift key
 
Last edited:

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
first thing first...

"appliesto" pretty much works for file types
so u can exclude small files like this:
"AppliesTo"="NOT System.Size:1..4kB"
this will skip context menu on files smaller than 4kB

so what u tryin to do with apllies to wont work

next...
your cmd command is probably wrong thats why it does not work with virtual folders
CMD.exe "%1" is not correct, "cmd.exe \"%V\"" would be correct alongside any other commands u want

next...
windows has this feature already to open CMD or Powershell in any folder/background/drive context menu which is what u tryin to replicate here
it gets activate if you hold shift key and then right click on folder or empty space inside folder, ull get two options there, open command window here/open powershell window here

if u dont want to hold shift key to get that "feature" in context menu
open regedit
HKCR\Drive\Shell\cmd
HKCR\Directory\Shell\cmd
HKCR\Directory\Background\Shell\cmd
HKCR\Drive\Shell\Powershell
HKCR\Directory\Shell\Powershell
HKCR\Directory\Background\Shell\Powershell
delete "Extended" in all these (thats teh shift key context menu) and it will appear in context menu without shift key
Thank you for your reply.

Just as a reference, I use registry modifications posted on tenforums.com

1. So the AppliesTo string only works with files and not directories or folder paths correct? When I add AppliesTo string to HKCR\Directory\shell and HKCR\Directory\Background\shell, without a value or with an incorrect syntax, the right-click option disappears for ALL folders, not just regular, non-library folders, just an FYI.

I am trying to adapt the AppliesTo string to a path as in this tenforums tutorial which adds "take ownership" to right-click menu. If you look at the registry file, Add Take Ownership to Context Menu in Windows 10 | Tutorials (tenforums.com)
the author specifically keeps "take ownership" from showing up on critical drives like the c drive, program files, program data, using the following string and value:

"AppliesTo"="NOT (System.ItemPathDisplay:=\"C:\\Users\" OR System.ItemPathDisplay:=\"C:\\ProgramData\" OR System.ItemPathDisplay:=\"C:\\Windows\" OR System.ItemPathDisplay:=\"C:\\Windows\\System32\" OR System.ItemPathDisplay:=\"C:\\Program Files\" OR System.ItemPathDisplay:=\"C:\\Program Files (x86)\")

So using the System.ItemPathDisplay, would it not be possible to use NOT System.ItemPathDisplay variable with path to libray to omit the libraries?


2. I am using this command prompt registry modification here: https://www.tenforums.com/tutorials/158472-add-remove-command-prompt-open-here-context-menu-windows-10-a.html
It adds both a regular and administrative command prompt in one flyout menu.

The registry value for the regular command prompt is

"cmd.exe /s /k pushd \"%V\""

and for the administrative prompt is

"cmd /c echo|set/p=\"%L\"|powershell -NoP -W 1 -NonI -NoL \"SaPs 'cmd' -Args '/c \"\"\"cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe\"\"\"' -Verb RunAs\""

Are they not correct? They seem to work.

Your point about the command not being right led me to think of another idea. Rather than try to exclude libraries from an AppliesTo string, can the actual command value be modified to exclude libraries?

3. I usually hide the default powershell menu in windows and install PowerShell 7 and use those context menu entries. I also hide the default command prompt and use the registry modification posted at tenforums. I am familiar with the Extended string and it does hide hide the context menu options from regular view but I am trying to learn a little about the guts of the registry and would like a more elegant solution to the issue.

Thanks!
 

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
first thing first...

"appliesto" pretty much works for file types
so u can exclude small files like this:
"AppliesTo"="NOT System.Size:1..4kB"
this will skip context menu on files smaller than 4kB

so what u tryin to do with apllies to wont work

next...
your cmd command is probably wrong thats why it does not work with virtual folders
CMD.exe "%1" is not correct, "cmd.exe \"%V\"" would be correct alongside any other commands u want

next...
windows has this feature already to open CMD or Powershell in any folder/background/drive context menu which is what u tryin to replicate here
it gets activate if you hold shift key and then right click on folder or empty space inside folder, ull get two options there, open command window here/open powershell window here

if u dont want to hold shift key to get that "feature" in context menu
open regedit
HKCR\Drive\Shell\cmd
HKCR\Directory\Shell\cmd
HKCR\Directory\Background\Shell\cmd
HKCR\Drive\Shell\Powershell
HKCR\Directory\Shell\Powershell
HKCR\Directory\Background\Shell\Powershell
delete "Extended" in all these (thats the shift key context menu) and it will appear in context menu without shift key
Please see the above reply. Additionally....

I have another idea. If you open file explorer, and select file from the menu bar, the native ribbon powershell and command prompt options are greyed out in libraries but active in a standard folder. From what I understand, there is some sort of command store set of keys that handle all of the options for explorer. Can you find the key that handles the command prompt and/or powershell for the ribbon and apply it to the context menu entries? In other words, is there a way to exploit the inability of command prompt and/or powershell to open a shell in virtual folders and apply the same to the context menu?
 

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
first thing first...

"appliesto" pretty much works for file types
so u can exclude small files like this:
"AppliesTo"="NOT System.Size:1..4kB"
this will skip context menu on files smaller than 4kB

so what u tryin to do with apllies to wont work

next...
your cmd command is probably wrong thats why it does not work with virtual folders
CMD.exe "%1" is not correct, "cmd.exe \"%V\"" would be correct alongside any other commands u want

next...
windows has this feature already to open CMD or Powershell in any folder/background/drive context menu which is what u tryin to replicate here
it gets activate if you hold shift key and then right click on folder or empty space inside folder, ull get two options there, open command window here/open powershell window here

if u dont want to hold shift key to get that "feature" in context menu
open regedit
HKCR\Drive\Shell\cmd
HKCR\Directory\Shell\cmd
HKCR\Directory\Background\Shell\cmd
HKCR\Drive\Shell\Powershell
HKCR\Directory\Shell\Powershell
HKCR\Directory\Background\Shell\Powershell
delete "Extended" in all these (thats teh shift key context menu) and it will appear in context menu without shift key
Please see my additional comments/questions.
 
You don’t need to add anything to the registry and I don’t know why you were doing it. This is how you mess up windows. All you have to do is hover your mouse over a folder, press the SHIFT key and right mouse click. Then you can select to open a command window or power shell depending on how your system is set up
 
Last edited:
Reactions: Ralston18

bamajon1974

Prominent
Aug 27, 2019
34
0
530
0
You don’t need to add anything to the registry and I don’t know why you were doing it. This is how you mess up windows. All you have to do is hover your mouse over a folder, press the SHIFT key and right mouse click. Then you can select to open a command window or power shell depending on how your system is set up
  1. I am adding functionality to the right click menu that isn't already present, i.e., open a command prompt or powershell window as an admin.
  2. I am comfortable with editing the registry and always backup the existing configuration prior to any changes.
  3. Adding admin command prompt options to context menu entries are well-known registry tweaks and have been published in many reputable sites, like tenforums, for many years without damaging windows.
  4. The problem is, that the existing right click entries already present by default, whether admin or not, are also added to libraries and apparently Explorer cannot open command prompt in virtual directories.
  5. What I would like to do is either (a) modify the string values that open the command prompt in the specific directory to also open in virtual folders, which, from subsequent discussions elsewhere, is not possible or (b) modify the registry entries to ignore libraries.
  6. I am not a coder nor programmer and do not know how to implement these modifications. These modifications, are, however, simple enough, that they shouldn't break windows if done correctly. That is why I ask the questions.
Does that help?
 

ASK THE COMMUNITY

TRENDING THREADS