«« Site Rescued »»

While the site is still going to move from its current host, a new site will now take its place. More Info.

The new site may have less content, but the core will now remain. And it will now play nicely with phones! Keep an eye on the DelphiDabbler Blog for news.

» Help

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.

Special extensions:

  • drive - drives.
  • folder - folders.

  sTypeName: string;
  with TRegistry.Create do
      RootKey := HKEY_CLASSES_ROOT;
      { Set the extension you want. Include the '.' character }
      OpenKey('.Extension', True);
      { Get file type name }
      sTypeName := ReadString('');
      { Create explorer extension. Instead of 'Open' put whatever you want. }
      OpenKey('' + sTypeName + 'ShellOpen', True);
      { The context menu item }
      WriteString('', 'Open in my application');

      OpenKey('' + sTypeName + 'ShellOpenCommand', True);
      { 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. }
      WriteString('', '"' + Application.ExeName + '" "%1"');

      { 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 constant
        string array with the file extensions. }
Author: Unknown
Added: 2007-06-02
Last updated: 2007-06-02

« Return to contents »