Question

I am currently using:

if ParamStr(1)<>'%1' then
begin
  address.Text:=ParamStr(1);
  autoconfigfile;
end;

to pick up the name of the file that was used to open the file with via file association.

I now want to develop the ability to operate on multiple files. I.e. if I select 5 files and right click and select open with "EncryptionSystem". I have the registry entry:

  reg.OpenKey('*\shell\Encrypt\command', true);
  reg.WriteString('','C:\Program Files\EncryptionSystem\EncryptionSystem.exe "%1"');
  reg.CloseKey;

To add a right click open ability to all files. I would then want the ability to detect

  1. how many files
  2. the pathname of each file
Was it helpful?

Solution

If you try to open multiple files at once you will generally get multiple instances of the registered program, each opening one of the files.

Now judging from your recent questions

How do i tell if one instance of my program is running?
How do I send a string from one instance of my Delphi program to another?

you do not wish to allow multiple instances of the program, so you will need to either reconsider that design decision, or implement one of the ways outlined in the answers to the second question to send the command line parameter of the secondary instances of your program to the first instance. Please note that timing is important here, because the first instance may well not yet be ready to receive the data from the other instances. Especially with solutions using the window handle of the main form, or some form of pipe- or file-based communication mechanism will involve waiting for the first instance to be ready. It may therefore be much easier to simply allow multiple instances of the program.

You may also want to look into this Microsoft Knowledge Base entry or search for more information about the DDE Execute command.

Edit: You could also try with "%*" instead of "%1" in the registry key, as detailed in the "Old New Thing" comment the answer by gabr mentioned. I haven't tested this, but it looks like it could work.

OTHER TIPS

Besides everything else, you should use %l instead of %1. That way your program will get a full (long) name of the file, not the short (DOS 8.3) one.

EDIT: An answer to Rob's question in comments

It seems that it's almost impossible to search for '%l' and '%1' (including percent sign) either using Google or MSDN search. :( However, I found a pretty good description in The Old New Thing - '%1' autodetects whether your program supports long file names and passes either short or long name. It seems that all modern systems pass long name unless your exe cannot be found (at least that's how I understand the Raymond's expose).

If you scroll further down in the comments (search for '%l' on the page) you'll find a list of all supported parameters, taken from some page that doesn't exist anymore (but I found an old copy in the Internet Archive). That page doesn't include no reference to Microsoft documentation either, so I can't give you an authoritative link :(

Rob, thank's for asking - I now know more about %1/%l than before :) +1 for that.

Not sure what you really want. But you can find the number of parameters with:

ParamCount;

Each param is then found with

ParamStr(1);
ParamStr(2);
ParamStr(3);

Until ParamCount.

I note that you are only registering it with %1.

I would try %1 %2 %3 %4 %5 etc in the registry.

I have never played with shell extensions to see what else might be making this fail. All I've done is registered file associations and they behave exactly as I would expect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top