Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to recieve information from ShellExecute 1

Status
Not open for further replies.

eladna

Programmer
Dec 11, 2002
17
IL
Hi
I have 2 programs which one opens the other with ShellExecute command.
For example

Code:
procedure Tform1.Button1Click(Sender: TObject);
begin
ShellExecute(0, 'open', PChar(ExtractFilePath(Application.ExeName)+'SecondProgram.exe'),
Pchar('Parameters to pass'), Pchar('Directory to pass'), SW_SHOW);
end;

The question is how to receive the information from the first program?

Thanks.
 
It depends on what information you are looking for.
Also do you want the programms to run concurrently?
If the first program can wait until the called program has been terminated then consider using 'CreateProcess()' rather than shellexecute.

There are example of both types of call in the FAQ section.
and how to check returned values.
faq102-6048 and faq102-5462

Or do you want to monitor the other program while it runs?

Steve [The sane]: Delphi a feersum engin indeed.
 
I'm asking about the loaded program.
When it starts, how can I tell it has been started from the first program by ShellExecute command (and not by double click on the exe file), and how to receive the parameters that ShellExecute pass (as shown at the sample)
 
Still not sure what you are getting at by the 'first program' do you mean the Delphi application code example?

This seems to call an application 'secondprogram.exe' that resides in the same folder as the Delphi application.

If shellexecute failed to start the program it will return a value of <32.

if you are trying to monitor both programs with a third program, then I don't know of any way to determine the calling source.
If you use Createproccess then the Delphi program IS the owner of the second program.



Steve [The sane]: Delphi a feersum engin indeed.
 
I have 2 Delphi programs, I wrote them both.
Now, the first program calls the second one and tells it to do something (like push a certain button or read a string).
I don't have a problem to open the second program (with ShellExecute) and of I did it correct send it parameters.
The problem is, and this is my question, how in the second program I read the information that the first program has sent it when open.

I hope I'm clear this time
And thanks again.
 
Ah I think I see now look at 'ParamStr' in the help file

Code:
The following example beeps once for each “beep” passed in on the command line. The example terminates the application if  “exit” is passed in on the command line.

procedure TForm1.FormCreate(Sender: TObject);

var
  i: Integer;
  for i := 1 to ParamCount do
  begin
    if LowerCase(ParamStr(i)) = 'beep' then
      Beep
    else if LowerCase(ParamStr(i)) = 'exit' then
      Application.Terminate;
  end;
end;

Steve [The sane]: Delphi a feersum engin indeed.
 
Thank you, it's working with the ShellExecute, but if I'm calling the second program with this function
FAQ102-6048:
I cant read the parameters (which are which file to open and which PATH)

Any help would be appreciated
 
Try putting the parameters into the parameters field of CreateProccess. The example adds them onto the filename as you would do in a console call, but this does not always give the expected result.
CreateProccess has a separate field for parameters not used in the example, usage depends on circumstances.


Steve [The sane]: Delphi a feersum engin indeed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top