Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Execute an exe within a c++ app

Status
Not open for further replies.

davidmelvin

Technical User
Nov 3, 2000
13
US
I would like to execute an executable file (exe) that is located in the same directory as my application. I don't want the cmd.exe window to pop up when it happens. So I don't want to use system(), or do I? It would be fine to use system() if the window would quickly disappear when it executed.

I am using c++ Builder. This operation will happen without user interface. The user will click a button that will start a sequence of operations including executing the exe.

Thank you for your help.
David
 
Call CreateProcess to execute your exe !
...
SI : TStartupInfo;
PI : TProcessInformation;

FillChar(SI, SizeOf(SI), 0);
SI.cb := SizeOf(SI);
SI.dwFlags := STARTF_USESHOWWINDOW;
SI.wShowWindow := SW_HIDE ;

CreateProcess(
Nil ,
PChar('ExeFile') ,
Nil , Nil , True , 0 , Nil , Nil , SI , PI ) ;
.....

Hope this Delphi code snipper will help you!

 
I use:

if(WinExec(&quot;complete path to desiredProgram.exe&quot;, SW_SHOWNORMAL) < 32) {
ShowMessage(&quot;I can't run: desiredProgram.exe&quot;);
// Take whatever other failure action here
}
else {
// Take whatever success action here
}
-mark-
 
if it's a console/dos app you want to execute just use:


#include <process.h>
...
spawnl(P_DETACH, &quot;PROGNAME&quot;, &quot;PROGNAME&quot;, NULL);
 
As far as I remember there also exists one function as ShellExecute. John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top