files selected in the file explorer

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I would like to be able to tell what file or files have been highlighted
in Windows Explorer and pass this is in as an array into a .NET application.
Basically I would like to be able for a user to select a couple files and
right click and run my app which would do something with these files.
I assume I have to use the w32 api, but which methods?

thanks in advance
 
Hi,

You need to look into Shell Integration. There is firstly the limited but
simple solution.
Add a registry key to extend the context menu for explorer.

[HKEY_CLASSES_ROOT\*\shell\My Shell Command\Command]
@= "c:\\MyCoolApp.exe %1"

The * means any file, My Shell Command is the menu item text that is added
to the context menu and
@= "c:\\MyCoolApp.exe %1" sets the default value fot the key 'Command' the
%1 represents the command line parameter that is passed to your application
ie. the selected file. For multiple selection this will fire your app once
for each selected item. If your app is made a single instance then
subsequent instances can forward the data from to the primary instance
before closing themselves.

Another option is to look at the more extensive Shell Extensions. I have
only ever done this from C++ and have never attempted it from .NET but it
can probably be done. For this you need to develop an in-process COM server,
the server must implement the required interfaces to integrate with the
shell, for your purposes IContextMenu and IShellExtInit should do.

This is a larger topic than can be addressed in this post, but I am sure
this will give you enough information to begin your search.

Hope this helps
 
Back
Top