1

How can I create a Windows Explorer command bar tool that takes a dynamic string?

I already know how to add my tool to the command bar and execute the command on click.

enter image description here

But I need a toolbar like the second one after Organize.

I need that when I click to the file name of my tool be like My Tool - File name (selected.txt) or My Tool - Selected File Extension (.txt).

Does anyone have an idea about how to do that?

J0e3gan
  • 8,740
  • 10
  • 53
  • 80

1 Answers1

3

1) Create a shell extension. Your shell extension must implement IInitializeCommand, IObjectWithSite, IObjectWithSelection, IExplorerCommand and IExplorerCommandState.

2) Register your shell extension:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\YourCommandID]
@=YourTopCommandCaption
ExplorerCommandHandler=YourCLSID

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FolderTypes\{5c4f28b5-f869-4e84-8e60-f11db97c5cc7}\TasksItemsSelected]
@=YourCommandID

If default value of TasksItemsSelected key is not empty you MUST add new string to old! For example prev value is Windows.copy the new must be Windows.copy;YourCommandID

{5c4f28b5-f869-4e84-8e60-f11db97c5cc7} is FOLDERTYPEID_Generic.

3) IExplorerCommand.GetFlags must return ECF_HASSUBCOMMANDS or ECF_ISDROPDOWN

4) IExplorerCommand.EnumSubCommands must return object implements IEnumExplorerCommand

5) IEnumExplorerCommand.Next must return object implements IExplorerCommand, IObjectWithSite and IObjectWithSelection. Every object is a single command of sub menu.

It works only on Win7.

Denis Anisimov
  • 3,297
  • 1
  • 10
  • 18
  • Thanks a lot! -Is there a way to display and icon for this button? Thanks in advance! – GeekUser Oct 10 '14 at 21:10
  • What is interesting: Iobit uninstaller shell extension doesn't register at CommandStore & FolderTypes.. that's why I though it's a hack... – GeekUser Oct 10 '14 at 21:17
  • @GeekUser IExplorerCommand has method GetIcon but in my experiments it was never called. – Denis Anisimov Oct 11 '14 at 06:29
  • Denis, looks like you've successfully solved the issue of putting icon there (shellace library) Can you please share this secret? :) – GeekUser Jan 06 '15 at 15:55
  • @GeekUser Cannot confirm. Why do you think I solved the issue? – Denis Anisimov Jan 06 '15 at 22:01
  • Vista supposedly called GetIcon. Now that Win11 is forcing everyone to re-implement all context menu items as IExplorerCommand for the stupid new menu we might see GetIcon getting called again... – Anders Sep 11 '21 at 10:29