Solved

Execute an external program from a delphi application

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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