Run external applications: ShellExecute ve ShellExecuteEx

Run external applications: ShellExecute ve ShellExecuteEx

How do I run an external program from a Delphi program?

The Delphi programming language provides a quick way to write, compile, package, and distribute cross-platform applications. Although Delphi creates a graphical user interface, there may not be times when you want to execute a program from your Delphi code. Suppose you have a database application that uses an external backup program. The Backup utility picks up parameters from the application and backs up your data, waiting until your program is backed up.

Maybe you want to open the documents presented in a file list box by double-clicking on them before opening the corresponding program. In your program, consider a link tag that takes the user to your homepage. You may also be interested in sending an email directly from Delphi through the default Windows email client program.

  1. How do I open my browser with a local HTML page?
  2. How to navigate a site, how to open an external HTML page with a Delphi application?
  3. How can I hold my Delphi program until the external program is terminated?
  4. Can I print documents from within my program without explicitly launching the application that created the document, for example: Can you print a Word document without starting Word?

Mak There are several functions available just to run an external application or open a saved file, open a folder, print a file, and so on.

In most cases, the ShellExecute Windows API function is used.

It gives a degree of control and is also not very complicated. A few examples:

Start an application:

ShellExecute (Handle, n open il, PChar (.exe c: \ test \ app.exe (), nil, nil, SW_SHOW);


Start NotePad and upload a file: (You do not need to specify the full path, the system finds notepad.exe):

ShellExecute (Handle, n open ’, PChar (\ notepad‘), PChar (’c: \ test \ readme.txt’); nil, SW_SHOW);


Print a document:

ShellExecute (Handle, n print ’, PChar (oc c: \ test \ test.doc (), nil, nil, SW_SHOW);

Note: You will probably see the window of the Word program in a very short time, but it will close automatically.

Open an HTML page that is local or remote, ie:

ShellExecute (Handle, n open il, PChar (estra (), nil, nil, SW_SHOW);

You can do this with any type of registered data, for example;

  • Text file:
ShellExecute (Handle, n open il, PChar (xt c: \ test \ readme.txt (), nil, nil, SW_SHOW);
  • HTML Help File:
ShellExecute (Handle, n open il, PChar (c. c: \ windows \ help \ calc.chm (), nil, nil, SW_SHOW);
  • Open a folder with Windows Explorer:
  • ShellExecute (Handle, n explore il, PChar (windows c: \ windows) har, nil, nil, SW_SHOW);
  • Run a DOS command and return immediately:
ShellExecute (Handle, n open ’, PChar (xt file), PChar (‘ / c copy file1.txt file2.txt ’), nil, SW_SHOW);
  • Run a DOS command and keep the DOS window open:
ShellExecute (Handle, n open ’, PChar (‘ PC), PChar (‘/ k dir’), nil, SW_SHOW);