6 12 Votes

Delphi: Execute external Program and pass Parameters

Tip by Delphian | 06/05/2013 at 12:17

After I have shown how to start another program out of your Delphi application in this tipp, I would like to show you now, how to pass parameters to the external application. I would like to show you 2 alternatives for this.

Alternative 1: WinExec

The function WinExec comes with a small number of parameters:

WinExec('C:\prog.exe param1 param2', SW_SHOW);

Here, we are starting the program "C:\prog.exe" and we are passing the parameters "param1" and "param2" to the program. So, as a first parameter, we are passing the command line and as a second parameter, we can define how the program should be displayed.

Alternative 2: ShellExecute

But it is also possible to pass parameters by using the ShellExecute function. Here is the same example carried out with the help of ShellExecute:

uses ShellApi;
var parameter: String;

parameter:='param1 param2';

ShellExecute(0, 'open', 'C:\prog.exe', PChar(parameter), nil, SW_SHOW);

Important: When passing a string as parameter, we have to use PChar() before.

ReplyPositiveNegative

About the Author

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own articles on askingbox.com. How to do.