How to exclude libraries from custom right-click menu entries

Page 1 of 3 123 LastLast

  1. Posts : 521
    Win7 Pro X64, Win10 Pro x640
       #1

    How to exclude libraries from custom right-click menu entries


    I want to add a custom context menu entry to open an administrator command prompt when right-clicking a directory or directory background. I borrowed the registry modification code (shown below) from tenforums and works fine.

    However, I found that the command prompt context menu is also added to library folders and backgrounds. It seems that command shell windows cannot be open in such a way for hardlinks like Libaries. Note that no registry information was entered for the HKCR\LibraryFolder\Background\Shell, HKCR\AllFileSystemObjects\Shell nor HKCR\Folder\Shell subkeys.

    I would like to exclude Libraries and Library backgrounds from displaying the command prompt context menu and think I can do so using the AppliesTo string, but don't know how the proper syntax for values. If I simply add AppliesTo string with value "NOT Libraries" to HKCR\Directory\shell\CommandPrompt\shell\cmdadmin and/or Directory\Background\Background\shell\CommandPrompt\shell\cmdadmin subkeys, the right-click menu entries disappear for ALL folders and/or folder backgrounds.

    Questions:

    1. What is the proper format/syntax for the values of AppliesTo string to exclude the custom context menu entry from library folders and library backgrounds?
    2. Does the AppliesTo string need to be added to either HKCR\Directory or HKCR\Directory\Background or both keys?

    Thanks!

    From: Add or Remove Command Prompt Open Here Context Menu in Windows 10

    Code:
    [HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\shell\cmdadmin]
    @="Open here as administrator"
    "HasLUAShield"=""
    "Icon"="imageres.dll,-5324"
    
    [HKEY_CLASSES_ROOT\Directory\shell\CommandPrompt\shell\cmdadmin\command]
    @="cmd /c echo|set/p=\"%V\"|powershell -NoP -W 1 -NonI -NoL \"SaPs 'cmd' -Args '/c \"\"\"cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe\"\"\"' -Verb RunAs\""
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\CommandPrompt\shell\cmdadmin]
    @="Open here as administrator"
    "HasLUAShield"=""
    "Icon"="imageres.dll,-5324"
    
    [HKEY_CLASSES_ROOT\Directory\Background\shell\CommandPrompt\shell\cmdadmin\command]
    @="cmd /c echo|set/p=\"%V\"|powershell -NoP -W 1 -NonI -NoL \"SaPs 'cmd' -Args '/c \"\"\"cd /d',$([char]34+$Input+[char]34),'^&^& start /b cmd.exe\"\"\"' -Verb RunAs\""
      My Computer


  2. Posts : 68,894
    64-bit Windows 11 Pro for Workstations
       #2

    Hello,

    Removing the key below will remove it from Library backgrounds, but it will also remove it from folder backgrounds.

    HKEY_CLASSES_ROOT\Directory\Background\shell\CommandPrompt\shell\cmdadmin
      My Computers


  3. Posts : 521
    Win7 Pro X64, Win10 Pro x640
    Thread Starter
       #3

    Correct. I experimented with adding and removing the the registry keys to confirm. I still think the way to go is to use "AppliesTo" string with "NOT" value followed, in parentheses, by a canonical name, like Libraries, or system.itempathdisplay to user libraries to exclude Libraries in Directory Key and Library Backgrounds in Directory\Background key but I don't know how to format the values. Is there a specific way to format paths to hard links? Can the paths be relative or absolute? Is there some system name for Libraries, like Libraries-ms or something, that I should be using?

    I have very little knowledge of coding and the inner workings of windows otherwise I could figure it out easier.
      My Computer


  4. Posts : 68,894
    64-bit Windows 11 Pro for Workstations
       #4

    I would agree, but I'm not aware of a value for Libraries in the "AppliesTo" "NOT" option.
      My Computers


  5. Posts : 521
    Win7 Pro X64, Win10 Pro x640
    Thread Starter
       #5

    @KeithM

    Can you help please? You know a lot about registry modification.
      My Computer


  6. Posts : 3,274
    Win10
       #6

    Hopefully, Keith has a better idea about how the the Background keys work. From what I have tested, as soon as you put a String Value with "AppliesTo" in "Background" keys, the menu item stops working regardless of whether you leave the AppliesTo string blank or not. For example if I create a simple "cmd-Test-dir" key under Computer\HKEY_CLASSES_ROOT\Directory\shell and in ApppliesTo I enter:
    NOT System.ItemFolderPathDisplay:"C:"
    The menu item appears when right clicking any Directory 'except' when it is on any directory under drive C: as expected.

    But when the same is done under Computer\HKEY_CLASSES_ROOT\Directory\Background\shell, the command disappears as soon as I set up an "AppliesTo" string whether it is blank or with the same contents as the one shown above.
      My Computers


  7. Posts : 521
    Win7 Pro X64, Win10 Pro x640
    Thread Starter
       #7

    das10 said:
    Hopefully, Keith has a better idea about how the the Background keys work. From what I have tested, as soon as you put a String Value with "AppliesTo" in "Background" keys, the menu item stops working regardless of whether you leave the AppliesTo string blank or not. For example if I create a simple "cmd-Test-dir" key under Computer\HKEY_CLASSES_ROOT\Directory\shell and in ApppliesTo I enter:
    NOT System.ItemFolderPathDisplay:"C:"
    The menu item appears when right clicking any Directory 'except' when it is on any directory under drive C: as expected.

    But when the same is done under Computer\HKEY_CLASSES_ROOT\Directory\Background\shell, the command disappears as soon as I set up an "AppliesTo" string whether it is blank or with the same contents as the one shown above.
    I noticed that using AppliesTo string with no variable also hides the context menu for all folders. There is a specific registry key for Libraries HKCR\Libraries\Background\Shell that is not modified, yet the context menu entries still show up on libraries and library backgrounds.

    I was thinking of some sort of string and value like:

    "AppliesTo"="NOT (System.ItemPathDisplay:="C:\\{path})" where {path} would be the absolute or relative directory path to the library in question.

    Do you know what the paths the libraries are? Or would it be better to modify the HKCR\Folder\Shell or HKCR\AllFileSystemObjects\Shell keys?
      My Computer


  8. Posts : 989
    Microsoft Windows 10 Home
       #8

    bamajon1974 said:
    @KeithM

    Can you help please? You know a lot about registry modification.
    Hi. Started playing with this yesterday. My initial feeling was that Explorer shouldn't even be offering commands defined under 'HKCR\Directory' to display for the Library folder, and perhaps clearing some of the SFGAO flags found under:
    Code:
    HKEY_CLASSES_ROOT\CLSID\{031E4825-7B94-4dc3-B131-E946B44C8DD5}\ShellFolder\Attributes
    and may sitll explore that. But I had never paid much attention to the AppliesTo value, and searched the regsitry for some examples. Found this under HKCR\Folder\Shell\pintohome:
    Code:
    System.ParsingName:<>"::{679f85cb-0220-4080-b29b-5540cc05aab6}" AND System.ParsingName:<>"::{645FF040-5081-101B-9F08-00AA002F954E}" AND System.IsFolder:=System.StructuredQueryType.Boolean#True
    Under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{A302545D-DEFF-464b-ABE8-61C8648D939B}

    The ParsingName for UsersLibrariesFolder is defined as "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}" (The same value that is insered into the Desktop namespace)

    So I added an AppliesTo value with the string System.ParsingName:<>"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}"

    Which in a .reg file will look like:
    Code:
    "AppliesTo"="System.ParsingName:<>\"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\""
    At first I only restrated the Shell. That was insufficient for the value to be recognized. But after a restart (sign out/sign in may work as well), the Directory command disappeared from the Library folder context menu while still appearing & functioning elsewhere. But this doesn't work for Background (kills it everywhere).

    Here's a demo file:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\Test]
    @=""
    "AppliesTo"="System.ParsingName:<>\"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\""
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\Test\Command]
    @="powershell  -NoExit -Command \"'%V' | echo\""
      My Computer


  9. Posts : 521
    Win7 Pro X64, Win10 Pro x640
    Thread Starter
       #9

    KeithM said:
    Hi. Started playing with this yesterday. My initial feeling was that Explorer shouldn't even be offering commands defined under 'HKCR\Directory' to display for the Library folder, and perhaps clearing some of the SFGAO flags found under:
    Code:
    HKEY_CLASSES_ROOT\CLSID\{031E4825-7B94-4dc3-B131-E946B44C8DD5}\ShellFolder\Attributes
    and may sitll explore that. But I had never paid much attention to the AppliesTo value, and searched the regsitry for some examples. Found this under HKCR\Folder\Shell\pintohome:
    Code:
    System.ParsingName:<>"::{679f85cb-0220-4080-b29b-5540cc05aab6}" AND System.ParsingName:<>"::{645FF040-5081-101B-9F08-00AA002F954E}" AND System.IsFolder:=System.StructuredQueryType.Boolean#True
    Under HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderDescriptions\{A302545D-DEFF-464b-ABE8-61C8648D939B}

    The ParsingName for UsersLibrariesFolder is defined as "::{031E4825-7B94-4dc3-B131-E946B44C8DD5}" (The same value that is insered into the Desktop namespace)

    So I added an AppliesTo value with the string System.ParsingName:<>"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}"

    Which in a .reg file will look like:
    Code:
    "AppliesTo"="System.ParsingName:<>\"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\""
    At first I only restrated the Shell. That was insufficient for the value to be recognized. But after a restart (sign out/sign in may work as well), the Directory command disappeared from the Library folder context menu while still appearing & functioning elsewhere. But this doesn't work for Background (kills it everywhere).

    Here's a demo file:

    Code:
    Windows Registry Editor Version 5.00
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\Test]
    @=""
    "AppliesTo"="System.ParsingName:<>\"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}\""
    
    [HKEY_CURRENT_USER\SOFTWARE\Classes\Directory\shell\Test\Command]
    @="powershell  -NoExit -Command \"'%V' | echo\""
    Thank you@KeithM for your reply. I have some follow up comments/questions.... @Brink you may be interested in this thread.

    1. If clearing SFGAO flags helps remove the context menu entries from libraries, that would be the easiest solution. Please keep me posted about this.

    2. If I understand you correctly, rather than use some sort absolute or relative path to libraries, such as %appdata%\Microsoft\Windows\Libraries or C:\{user name}\appdata\roaming\microsoft\windows\libraries, you are using a CLSID assigned to library folders, correct?

    3. Additionally, if I understand you correctly, "AppliesTo"="System.ParsingName:<>"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}"" applied to Directory\Shell preserves the custom context menu entry for folder right-click but excludes the library folder, right? But the same string and value in Directory\Background\Shell excludes all folder backgrounds, including libraries, right?

    4. (This question backs up a little in anticipation of my next question) What is the difference between AllFileSystemObjects, Folder and Directory in HKCR? My understanding is that AllFileSystemObjects deals with all files and all folders, including regular folders and shell folders like libraries and This PC. I really don't know the difference between Folder and Directory but the registry entries are very different.

    4. Would it be more appropriate to add the custom command prompt context menu entry to AllFileSystemObjects and/or Folders? And use the AppliesTo NOT string/value here?

    5. Would it be possible to use a path in AppliesTo in this syntax? AppliesTo"="NOT (System.ItemPathDisplay:="\Documents.library-ms")" but in the correct syntax (not sure how to make this the right path)?

    6. Alternatively, rather than messing around with an AppliesTo string, would it be easier to modify Brink's command values to enter arguments that would either cause library paths to show up? Or exclude them?

    Thanks!
      My Computer


  10. Posts : 989
    Microsoft Windows 10 Home
       #10

    bamajon1974 said:
    1. If clearing SFGAO flags helps remove the context menu entries from libraries, that would be the easiest solution. Please keep me posted about this.
    1. No luck here, even stripped down to 0x20040000 (the flags needed to appear in the Navigation Pane and expand to show subfolders), the menu options stilll display.


      2. If I understand you correctly, rather than use some sort absolute or relative path to libraries, such as %appdata%\Microsoft\Windows\Libraries or C:\{user name}\appdata\roaming\microsoft\windows\libraries, you are using a CLSID assigned to library folders, correct?
    2. Yes, I'm using the CLSID because that is the namespace path to the virtual folder, "Librarires", rooted in the virtual Desktop. The ParsingName value found under HKLM\...\FolderDescriptions\<KnownFolderID> is the namespace path. And when I saw it used in other entries, it seemed the best way to exclude the LIbraries folder. The paths you reference refer to acutal file system locations which handle the menu commands just fine. But Explorer has no %V value to pass to your command when your command is launched from a virtual folder -- that's what causes the error.

      3. Additionally, if I understand you correctly, "AppliesTo"="System.ParsingName:<>"::{031E4825-7B94-4dc3-B131-E946B44C8DD5}"" applied to Directory\Shell preserves the custom context menu entry for folder right-click but excludes the library folder, right? But the same string and value in Directory\Background\Shell excludes all folder backgrounds, including libraries, right?
    3. Yes. Background seems to be a different animal. Even an AppliesTo test such as System.IsFolder:=System.StructuredQueryType.Boolean#True, which seems to always be true for Directories (and also works to exclude Libraries ), causes the command to disappear if specified for he Background command.

      4. (This question backs up a little in anticipation of my next question) What is the difference between AllFileSystemObjects, Folder and Directory in HKCR? My understanding is that AllFileSystemObjects deals with all files and all folders, including regular folders and shell folders like libraries and This PC. I really don't know the difference between Folder and Directory but the registry entries are very different.

      4. Would it be more appropriate to add the custom command prompt context menu entry to AllFileSystemObjects and/or Folders? And use the AppliesTo NOT string/value here?
    4. Files and directories are refer to actual file system items. AllFileSystemObjects includes both. Directories are a subset of Folders, but folders can also be virtual, with no corresponnding file system directory: Control Panel, Network, This PC, etc.
      Your command requires a valid directory path, right? If you defined it under HKCR\Folder, it would appear in even more loactions where it would throw an error. If you define it under AllFIleSystemObjects, it will appear in the context menu of every file & file sytem folder(directory), but it doesn't solve the background issue.How to exclude libraries from custom right-click menu entries-hkcr-namespace-venn-diagram.png

      5. Would it be possible to use a path in AppliesTo in this syntax? AppliesTo"="NOT (System.ItemPathDisplay:="\Documents.library-ms")" but in the correct syntax (not sure how to make this the right path)?
    5. I don't think that would make a difference. We already know two ways to exclude the Librarires from the regualr context menu, but no way to filter the background context menu.

      6. Alternatively, rather than messing around with an AppliesTo string, would it be easier to modify Brink's command values to enter arguments that would either cause library paths to show up? Or exclude them?
    6. Modify which commands?!?!? How!?!?!?
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 22:03.
Find Us




Windows 10 Forums