I couldn't find an official API to solve this, so I found an alternative solution.
The extension exposes the IExplorerCommand interface, but it can be used differently.
File Explorer calls extension methods in a different sequence when building the top-level context and the "Show More Options" menu.
Top-Level Menu:
Load(Parent = nil, Cmd)
- Cmd.GetState(ItemArray)
- Cmd.GetTitle(ItemArray)
- Cmd.GetIcon(ItemArray)
- Cmd.GetFlags
- while Cmd.Enum.Next = S_OK do Cmd.Load(Cmd, ItemArray)
Show More Options Menu:
Load(Parent = nil, Cmd)
- Cmd.SetSelection(ItemArray)
- Cmd.GetFlags
- Cmd.GetCanonicalName
- Cmd.GetToolTip
- Cmd.GetTitle(ItemArray)
- Cmd.GetIcon(ItemArray)
- Cmd.GetState(ItemArray)
- while Cmd.Enum.Next = S_OK do Cmd.Load(Cmd, ItemArray)
We can distinguish between the top-level menu and "Show more options" by monitoring the first call from File Explorer.
It is a fragile solution, but it works with current Windows 11 builds (I tried the official version and the latest Insider Preview).
I hope this helps other developers facing the same issue.