Solved

Execute an external program from a delphi application

Posted on 1997-04-05
3
289 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video discusses moving either the default database or any database to a new volume.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now