• Advertisement


This topic is now archived and is closed to further replies.

Executing a file

This topic is 5717 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I have a very basic question: How can I execute a file from within my running application? A very simple example would be that if the user presses a button, the file "sample.exe" is being launched... Delphi-specific answer if possible, plz! Yours, Indeterminatus --si tacuisses, philosophus mansisses--

Share this post

Link to post
Share on other sites
You can use ShellExecute, WinExec (now obsolete) or CreateProcess. Also, if you get the JCL then there''s a function called WinExec32, I believe.

If you want to use ShellExecute then the format is as follows:


procedure DoIt;
ShellExecute(Form1.Handle, ''open'', ''c:\windows\notepad.exe'',
nil, nil, SW_SHOWNORMAL);

Note that the nil parameters are for the parameters for your app and its working directory, in that order. Also, note that you have to pass it a handle as the first parameter: generally you can pass it a form''s handle or the application''s handle, or you can set it to 0. It opens the app using the default viewer (for files), which will in this case mean it just runs the program.

If you want to use strings remember to cast them to PChars first:

ShellExecute(Form1.Handle, ''open'', PChar(Filename),...);

Share this post

Link to post
Share on other sites

  • Advertisement