Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Execute an external program from a delphi application

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

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

837 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