Click here to Skip to main content
15,885,693 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am a beginner in winapi c++ on windows platform, i need to execute 3 exe files,i.e the installation programs, in one single program. i used shellexecute, exec v, system calls but all are exiting the program after the first program installation, please help me to solve this...

Thanking you in advance :)
Posted

1 solution

Here is your code, just copy your exe path to buff, for each of your exes, here I used notepads as exes, only when you close those notepads or exes closes it will not exit, I waiting for those to complete.

C++
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <tchar.h>

void _tmain( int argc, TCHAR *argv[] )
{
    STARTUPINFO si;
    PROCESS_INFORMATION pi;

    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );
    TCHAR buff[1024];
	ZeroMemory( buff, sizeof(buff) );
        //here you need to copy your exe path
	wcscpy(buff,L"C:\\Windows\\System32\\notepad.exe");
    // Start the child process 1.  
    if( !CreateProcess( NULL,   // No module name (use command line)
        buff,              
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return;
    }
	//here you need to copy your exe path
	// Start the child process 2. 
    if( !CreateProcess( NULL,   // No module name (use command line)
        buff,        
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return;
    }
    //here you need to copy your exe path	
    // Start the child process 3. 
    if( !CreateProcess( NULL,   // No module name (use command line)
        buff,        
        NULL,           // Process handle not inheritable
        NULL,           // Thread handle not inheritable
        FALSE,          // Set handle inheritance to FALSE
        0,              // No creation flags
        NULL,           // Use parent's environment block
        NULL,           // Use parent's starting directory 
        &si,            // Pointer to STARTUPINFO structure
        &pi )           // Pointer to PROCESS_INFORMATION structure
    ) 
    {
        printf( "CreateProcess failed (%d).\n", GetLastError() );
        return;
    }
    // Wait until child process exits.
    WaitForSingleObject( pi.hProcess, INFINITE );

    // Close process and thread handles. 
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
}
 
Share this answer
 
v4
Comments
Don_3 5-Dec-12 11:41am    
what should be the return value... for create process
Dharmateja Challa 10-Dec-12 8:45am    
its BOOL, checkout MSDN documentation its quite comprehensive...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900