How to create a shell extension using IExplorerCommand for Windows 11, 10, 8, and 7?

David Izada Rodriguez 41 Reputation points
2022-12-07T19:28:01.97+00:00

After reading Microsoft's documentation, Raymond Chen's blog, NanaZip implementation, and TortoiseSVN/TortoiseGit implementations, I created a "modern" shell extension implementing IClassFactory, IExplorerCommand, and IObjectWithSelection.
I also implemented several other interfaces but finally dropped them because they were unused.
When selecting two files, my context menu should appear like this:
268295-image.png

It works correctly after selecting both files and clicking Shift-F10 (that is, on the "Show More Options" submenu).
But it cannot render the "using >" submenu on the top-level menu.

268668-tlm-comparefiles.png

I tried the extension on Windows 7, registering the single root command (implementing IExplorerCommand and IObjectWithSelection), and it works as expected.

268724-comparefilesusing.png

Assuming that Windows 11 will not accept over one submenu, the only solution is to use a separator and render the submenu items after it.
In my case, it means to declare CompareFilesUsing as a separator, returning empty values for Title and Icon and ECF_ISSEPARATOR for GetFlags.
Of course, that should be only for Windows 11 on the top-level menu (how to know that is the case?).
In my case, after making the necessary changes, I got the following:

269081-nosubmenu-separator-light.png

There is something wrong here. There is no ">" announcing the submenu; the separator is just a blank line.
Is that correct? If not, what is happening?

How can my instances work under "Show More Options" and not on the top-level menu?

I have extensive logging in my extension, and I noticed that, even when Explorer uses the same DLL and instances, it follows different strategies for discovering the structure of the context menu provided by the extension. I'm attaching both logs for the command "Compare Files".
268352-tlm-comparefiles.txt => executing the command from the top-level Windows 11 menu
268266-smo-comparefiles.txt => executing the command from the "Show more options" submenu.

Analyzing the logs, it is noticeable that on the top-level menu, Explorer requests two instances of the root command.
This is part of my AppXManifest.xml:

  <Extensions>  
    <com:Extension Category="windows.comServer">  
      <com:ComServer>  
        <com:SurrogateServer DisplayName="Beyond Compare shell extension">  
          <com:Class Id="812BC6B5-83CF-4AD9-97C1-6C60C8D025C5" Path="BcShellEx64.dll" ThreadingModel="STA" />  
        </com:SurrogateServer>  
      </com:ComServer>  
    </com:Extension>  
    <desktop4:Extension Category="windows.fileExplorerContextMenus">  
      <desktop4:FileExplorerContextMenus>  
        <desktop5:ItemType Type="*">  
          <desktop5:Verb Id="AnyFile"               Clsid="812BC6B5-83CF-4AD9-97C1-6C60C8D025C5" />  
        </desktop5:ItemType>  
        <desktop5:ItemType Type="Directory">  
          <desktop5:Verb Id="AnyFolder"             Clsid="812BC6B5-83CF-4AD9-97C1-6C60C8D025C5" />  
        </desktop5:ItemType>  
      </desktop4:FileExplorerContextMenus>  
    </desktop4:Extension>  
  </Extensions>  

As my extension accepts files and folders, I had to declare my COM server and the extension category (fileExplorerContextMenus) with two verbs.
I don't know if that is why Explorer spawns two instances, but under "Show More Options," Explorer creates only one instance, while the top-level menu creates two (and uses only one).

Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,746 questions
Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,422 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,164 questions
{count} vote

Accepted answer
  1. Eugene Mayevski (Allied Bits) 85 Reputation points
    2023-01-18T07:37:20.22+00:00

    Assuming that Windows 11 will not accept over one submenu

    Yes, this is mentioned in MSDN, in one of the topics on IExplorerCommand.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful