1. Technology

Add Your Delphi Application as Item to Windows Explorer Folder Shell Menu

Let Your Application Be Executed When A Folder Is Right-Clicked in Explorer


Delphi Application In Shell Folder Popup Menu

Delphi Application In Shell Folder Popup Menu

Here's a neat trick to add an item to the right-click context popup menu for a folder in Windows Explorer.

When a users right-clicks on a folder in Windows Explorer (and TShellTreeView not to forget) a context popup appears. Beside standard items you can add an item for your application. When a user click the item - your application gets started and you can send it (as a parameter) the folder selected.

The EnsureShellFolderPopupItem procedure adds an entry in the Windows registry to start the application.

procedure EnsureShellFolderPopupItem(const itemName : string);
  with TRegistry.Create do
    if OpenKey('Directory\shell', true) then
      if OpenKey(itemName+'\command', true) then
        WriteString('', '"'+Application.ExeName+'" "%1"');
The above code ensures there's the following entry in the Registry (note that "itemName" is a string parameter in EnsureShellFolderPopupItem):

@="c:\...\myapplication.exe" "%1"

"c:\...\myapplication.exe" is the actual location of your Delphi application executable.

The OnCreate of a form gets the passed parameter and displays the folder path for the selected folder.

procedure TSomeForm.FormCreate(Sender: TObject);
  //make sure there is our item in shell folder's popup menu
  //not needed to call this every time but for testing ok ....

  EnsureShellFolderPopupItem('Process with my application');

  //show what folder has been selected to process
  if ParamCount > 0 then
    ShowMessage('APP started directly');
Not sure what application parameters are and how to process parameters in your application? Here's more info: Running Delphi Applications With Parameters, Parsing Command Line Parameters with Delphi, How to Run your Application by Double-Clicking on a File (Register Extension).

Delphi tips navigator:
» XPath To Select XML Nodes
« TTabSet/TTabControl Custom Tab Hints

©2014 About.com. All rights reserved.