Windows – How to create a shell context menu item that takes multiple files as arguments

context menuwindowswindows 7

Creating a Windows Shell context menu item that takes a single file as an argument is easy. See this question for an example.

However, how do you create a context menu item that takes multiple files as arguments? Say, for a diff-merge tool (in my case P4Merge), although the same technique would no doubt be applicable for other applications as well.

I've installed P4Merge but it does not add an item to the context menu automatically so I will have to do it manually.

When I tried using:

"C:\Program Files\Perforce\p4merge.exe" %1 %2

as the command line I got an error:

Errors: At least two files are needed. Cannot open only one file. P4Merge needs 0, 2, or 3 files.

When I tried using:

"C:\Program Files\Perforce\p4merge.exe" %0 %1

as the command line it opened two instances of P4Merge, one for each file.

It appears the correct file names are being passed through to %0 and %1 but a different instance of the P4Merge application is being executed for each one.

I currently have SourceGear's DiffMerge tool which has an item on the Shell context menu and that works beautifully, as I am able to select two files and use the context menu item to run a diff on them. I've trying searching the registry to see what arguments DiffMerge uses but I could not find a DiffMerge commandline that included arguments.

Best Answer

You can also try adding the program to the SendTo menu.

Related Question