Solved

Execute an external program from a delphi application

Posted on 1997-04-05
3
310 Views
Last Modified: 2010-04-06
I need to know what code should I use to run an external windows application from a delphi program

ex: if a user click on a button, then the application will launch wordpad for exemple or anyother program...

Can you help me? I already tried with
ExecProgram('wordpad.exe', 1);

but it doesn't work... or I must use a library I don't know...

Thanks

Patrick
0
Comment
Question by:pasta
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
mheacock earned 50 total points
ID: 1335184
Try
    WinExec (Delphi 1)
or
    CreateProcess  (Delphi 2+)
0
 
LVL 3

Expert Comment

by:mheacock
ID: 1335185
Did this help?  If you could grade this it would be appreciated.  Thanks.  If you need further assistance, just add a comment and I will answer shortly.
0
 

Expert Comment

by:maurik
ID: 1335186
procedure TForm3.Button1Click(Sender: TObject);
var
  Inst: THandle;
  PName: PChar;
  CommandLine: String;
begin
  PName := StrAlloc(101);
{Variable CommandLine will contain the windoows exe path and name}
  CommandLine := "c:\windows\write.exe";
  StrPCopy(PName,CommadLine);
  Inst := WinExec(PName, SW_NORMAL);
  while GetModuleUsage(Inst) > 0 do begin { is app finished? }
    Application.ProcessMessages; { Don't hog the system! }
    { Anything else you might want to do goes here }
  end;
  StrDispose(PName);
end;

This work with Delphi 1.0 . With Delphi 2.0 the procedure is as follows

procedure TForm3.Button1Click(Sender: TObject);
var
  Inst: THandle;
  PName: PChar;
  CommandLine: String;
begin
  PName := StrAlloc(101);
{Variable CommandLine will contain the windoows exe path and name}
  CommandLine := "c:\windows\write.exe";
  StrPCopy(PName,CommadLine);
  Inst := WinExec(PName, SW_NORMAL);
  StrDispose(PName);
end;

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question