How to Add a Context Menu Item to Windows Explorer

To add a context menu item to Windows Explorer you have create a few entries in the system Registry. First you have to get the file type’s name, add the context menu item and add then the command line. Besides files you can add context menus to drives or folders.<br>
Special extensions:<br>
- <i>.drive</i> - drives.<br>
- <i>.folder</i> - folders.
<pre>
<b>uses</b>
Registry;

<b> </b>var
sTypeName: <b>string</b>;
<b>begin
with</b> TRegistry.Create <b>do
try</b>
RootKey := HKEY_CLASSES_ROOT;
<i>{ Set the extension you want. Include the ‘.’ character }</i>
OpenKey(’.Extension’, True);
<i>{ Get file type name }</i>
sTypeName := ReadString(”);
CloseKey;

<i>(* Create explorer extension.
*
* Instead of ‘Open’ put whatever you want.
*)</i>
OpenKey(” + sTypeName + ‘ShellOpen’, True);
<i>{ The context menu item }</i>
WriteString(”, ‘Open in my application’);
CloseKey;

OpenKey(” + sTypeName + ‘ShellOpenCommand’, True);
<i>(* The commandline. Enter all the commandline options you need.
* Remember to use quotes for long file names with spaces. Even if your
* application’s filename doesn’t contain any spaces the folder that
* it’s in may contain them.
*
* %1 - is the selected file’s name.
*)</i>
WriteString(”, ‘”‘ + Application.ExeName + ‘” “%1″‘);
CloseKey;

<i>(* Repeat this for every file type you want to add a context menu to.
* For this operation you may want to use a for loop and a constat
* string array with the file extensions.
*)</i>
<b>finally</b>
Free;
<b>end</b>;
<b>end</b>;
</pre>

Tags: , , , , , , , , , , , , , ,

No Comments Yet

You can be the first to comment!

Leave a comment

OpenID Login

Standard Login