Create Shell Extension to command line tool

5

1

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?

cheesus says stop firing mods

Posted 2014-12-08T18:36:56.103

Reputation: 1 106

Answers

6

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

jValdron

Posted 2014-12-08T18:36:56.103

Reputation: 193