Delphi: Execute external Program and pass Parameters
Tip by Delphian | Last update on 2024-01-23 | Created on 2013-05-06
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.
About the Author
The author has not added a profile short description yet.
Show Profile
Related Topics
Windows Batch Script: Computer Shutdown
Tutorial | 2 Comments
Delphi/Lazarus: Command Line Parameter Tutorial Part 1: Sending
Tutorial | 0 Comments
Delphi/Lazarus: Command Line Parameter Tutorial Part 2: Receiving
Tutorial | 0 Comments
Delphi: Start other Application
Tip | 0 Comments
XAMPP: How to set up SSL/HTTPS for local Projects
Tutorial | 4 Comments
MIME Types of Microsoft Office File Formats
Info | 0 Comments
CSS: Include CSS Stylesheets in HTML
Tutorial | 0 Comments
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 article on askingbox.com. That’s how it’s done.