?
Solved

How to run an application in delphi?

Posted on 1999-12-18
9
Medium Priority
?
257 Views
Last Modified: 2010-04-06
I want to know how to run one application(.exe file) in another application?
0
Comment
Question by:dingcheng
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 2292111
Does ShellExecute or WinExec or CreateProcess help?
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2292557
to run an exefile
1.
put the FMXUtils unit in your uses clause
 
Syntax is
ExecuteFile( AppName, Parameters, StartDir, SW_showstyle);

e.g. ExecuteFile('Notepad.exe', '', '', SW_SHOWMAXIMIZED);

or
2.
WinExec('c:.\Myprog.EXE',SW_SHOWNORMAL);

Regards
Indi
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2293681
Appendix
you'll find FMXUtils  in
....\Borland\delphi\demos\doc\Filmanex
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
LVL 1

Accepted Solution

by:
Fatman121898 earned 150 total points
ID: 2294304
I do it this way:

function ExecApplication(APPName,cmdLine: String; ShowMode: DWord; WaitToExit: Boolean): DWord;
//executes as well WIN and DOS app
  var
    StartInfo: TStartupInfo;
    ProcInfo: TProcessInformation;
  begin
    StartInfo.cb:=SizeOf(StartInfo);
    FillChar(StartInfo,
             SizeOf(StartInfo), 0);
    StartInfo.dwFlags:=
      STARTF_USESHOWWINDOW;
    StartInfo.wShowWindow:=
      ShowMode;
    if AppName<>''
      then
        CreateProcess(PChar(APPName),
                      PChar(CmdLine),
                      nil, nil, False,
                      0, nil, nil,
                      StartInfo,
                      ProcInfo)
      else
        CreateProcess(nil,
                      PChar(CmdLine),
                      nil, nil, False,
                      0, nil, nil,
                      StartInfo,
                      ProcInfo);
    if WaitToExit
       then
         WaitForSingleObject    
                     (ProcInfo.hProcess,
                      INFINITE);
    GetExitCodeProcess
                     (ProcInfo.hProcess,
                      Result);
  end;

The core is API function CreateProcess.

Parameters:
APPName: application name (including path) - optional;
CmdLine: command parameters line;
ShowMode: visibility parameter (allowed values: SW_HIDE, SW_MAXIMIZE, SW_MINIMIZE and others - see
help info for ShowWindows API function);      
WaitToExit: wether to wait process to exit.

You could use CmdLine to pass applications name instead APPName.

Examples:

//statement:
ExecApplication('C:\MyProgs\ABC.EXE','-a -b -c', SW_MINIMIZE, False);
//is equal to:
ExecApplication('','C:\MyProgs\ABC.EXE -a -b -c', SW_MINIMIZE, False);

Jo.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2294554
Hi Fatman, how about writing a *comment* next time? You were not the first one in this thread...   :-)
0
 
LVL 1

Expert Comment

by:Fatman121898
ID: 2294720
Oops, sorry, didn't know that only the first one can write *answer*  .-)
Jo.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2294819
Well, of course you *can* write an answer, though you're not the first one. But here in the Delphi forum (and only here) most experts only write comments to give the questioner the possibility to choose the best comment. *I* post answers only, if I'm the first one and if I'm quite sure that my answer is really complete.

I wish EE would drop answers at all. Should be no problem now, since the questioners can accept any comment as the answer (new EE feature).
0
 

Author Comment

by:dingcheng
ID: 2294880
Thank Madshi and Indeferi.Thank you for your sincere help.  
0
 
LVL 1

Expert Comment

by:Indefrei
ID: 2296497
Lol :O)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
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…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…
Get the source code for a fully functional Access application shell with several popular security features that Access VBA application developers desire, but find difficult or impossible to figure out how to code. You get the source code for managi…
Suggested Courses
Course of the Month4 days, 15 hours left to enroll

601 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