I want to check for the existence and if it doesn’t exist add some actions in the Explorer’s right click (context) menu.
Besides of the above requirement (for which one can find easily solutions on web) I want to add one more:
Suppose that I register the following commands:
- “Command #1” – triggers ‘C:\MyProg.exe /cmd1’
- “Command #2” – triggers ‘C:\MyProg.exe /cmd2’
… (aso.)
How do I check if there is already a running instance of MyProg.exe and passing it the appropriate command/command line parameter together with the filename on which the user clicked?
(IOW, I want to use the already running instance of my program to do my task and not to open a new one)
A Delphi code snippet would be appreciated.
TIA
There are two ways to add items to the context menu.
Registry
This method is easy since it comes down to adding some registry keys. The downside is that you can’t put any logic in it. You can read about it here and here a simple example in Delphi. You get a bit more control if you are using DDE to execute the menu items. See here for a Delphi example. If DDE doesn’t solve your ‘already running’ problem you could try and have your applications communicate with each other trough some way of IPC.
Shell Extension
This method is a bit more work, but you can completely control the context menu from code. You would have to write a DLL, implement IContextMenu (or others) and register the dll with Windows Explorer. You can read about it here. You could also check out Shell+.