Reputation: 19690
I'm trying to create a program where it starts another .exe and itself just closes after the other program has started.
I currently have the following code:
#include <cstdlib>
int main( )
{
std::system( "checkpoint.exe" );
}
I can get checkpoint.exe
to start, but the starter program itself doesn't close until checkpoint.exe
closes. How would I get around this?
Upvotes: 0
Views: 4019
Reputation: 19690
The previous answer has some bugs. You have to initialize STARTUPINFO
and PROCESS_INFORMATION
structs, not LPSTARTUPINFO
or LPPROCESS_INFORMATION
. The latter are just pointers to the structs.
Here's a working solution:
#include <cstdlib>
#include <Windows.h>
int main( )
{
STARTUPINFO StartupInfo;
PROCESS_INFORMATION ProcessInfo;
ZeroMemory( &StartupInfo, sizeof( StartupInfo ) );
StartupInfo.cb = sizeof( lpStartupInfo );
ZeroMemory( &ProcessInfo, sizeof( ProcessInfo ) );
CreateProcess( "Program.exe",
NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
&StartupInfo,
&ProcessInfo
);
return 0;
}
Upvotes: 3
Reputation: 63775
Since you appear to be using Windows, you can use CreateProcess
LPSTARTUPINFO lpStartupInfo;
LPPROCESS_INFORMATION lpProcessInfo;
memset(&lpStartupInfo, 0, sizeof(lpStartupInfo));
memset(&lpProcessInfo, 0, sizeof(lpProcessInfo));
CreateProcess("checkpoint.exe"
NULL, NULL, NULL,
NULL, NULL, NULL, NULL,
lpStartupInfo,
lpProcessInfo
)
Upvotes: 5