Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 Smile | :)
Posted 30-Nov-12 1:25am
Don_3316

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
 
#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 );
}
  Permalink  
v4
Comments
Don_3 at 5-Dec-12 11:41am
   
what should be the return value... for create process
Dharmateja Challa at 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)

  Print Answers RSS
0 BillWoodruff 360
1 Mathew Soji 309
2 DamithSL 225
3 Afzaal Ahmad Zeeshan 202
4 Maciej Los 190
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 3,865


Advertise | Privacy | Mobile
Web01 | 2.8.1411019.1 | Last Updated 30 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100