Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Delphi with Other Programs

How do I execute another program from my Delphi Application? by towerbase
Posted: 6 Oct 04

This is surprisingly easy to do.  

First ensure that ShellApi is in a uses statement.


Uses ShellApi;
Then call ShellExecute.  This function takes six parameters but at its simplest it can be called as follows:


  ShellExecute(0, 'Open', PChar(App), PChar(''), PChar(''), SW_Hide);
Where App is the full path name of the application you wish to call OR it is the name of a file which is associated with an application.  


If you wish to start an application called 'MyApp.exe' from within your Delphi application then you would code something like


  ShellExecute(0, 'Open', PChar('c:\Apps\MyApp.exe'), PChar(''), PChar(''), SW_Hide);

If you have Microsoft Word installed on your computer then it is likely that


  ShellExecute(0, 'Open', PChar('c:\My Documents\Biography.doc'), PChar(''), PChar(''), SW_Hide);
would start Word and open your document called Biography.doc.

Parameter 4 allows you to pass parameters to your program.  For example, if your program required two digits as parameters then you would code something like:-


  ShellExecute(0, 'Open', PChar('c:\Apps\MyApp.exe'), PChar('123 999'), PChar(''), SW_Hide);
Parameter 5 allows you to specify a default directory to your application.  For example, your program might require a temporary directory:


  ShellExecute(0, 'Open', PChar('c:\Apps\MyApp.exe'), PChar('123 999'), PChar('c:\temp'), SW_Hide);
Note that the application that calls ShellExecute does not suspend whilst the called program is running.  Both programs will be executing at the same time.  The next FAQ (coming shortly) will show you how to suspend your program until the called program completes.

The Windows SDK Help provides details of what each of the parameters are used for and what the returned value from ShellExecute means.

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close