6

I have an existing command line tool which accepts a file/folder path as its only argument.

I want to create a Windows Explorer shell extension that, when invoked, runs the command line tool with the current path.

It's the same as the famous Open command line here, but with a different tool than cmd.exe.

Is that possible? How to do it?

8

There's a fairly easy way to do this if you know your way around the registry editor.

First of, open up regedit and navigate to HKEY_CLASSES_ROOT\Directory\shell.

There's a couple of locations where we can add those keys, HKEY_CLASSES_ROOT\Directory\shell will add an option in the context menu of folders.

You should have a couple of existing keys in there, most notably cmd which is the Open command window here option.

Once you're in that folder, let's create a new key (right click -> New -> Key), call it what you want. Now change the data of the (Default) value to whatever you want to be displayed in your context menu in Windows Explorer.

After you've created the key and changed the (Default) value's data

Now under your new key, you have to create another key called command and set it's (Default) data to the command you want to execute. You can use %V for the current folder. See this question for details about the arguments you can use: Which special variables are available when writing a shell command for a context menu

Now if you want to add an option when you click on Windows Explorer's background (any white space in the right pane of Explorer), you'll have to do the same thing, but add a key in HKEY_CLASSES_ROOT\Directory\shell\Background.

Example of a key in both the background and folders directory

If you want to add an option in the Context Menu for a specific file extension, you'll just have to find the proper class and add another key in it's shell folder like so:

Add a shell option to jpgs

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.