如何在程序中调用2个或更多shellexecute函数

如何在程序中调用2个或更多shellexecute函数

问题描述:

我是Windows平台上winapi c ++的初学者,我需要在一个程序中执行3个exe文件,即安装程序。我使用了shellexecute,exec v,系统调用但是在第一个程序安装完毕后都退出程序,请帮我解决这个问题...



提前感谢你:)

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 :)

这是你的代码,只需将你的exe路径复制到buff,对于你的每个前任,这里我只使用笔记本作为exes,只有当你关闭那些记事本或exes关闭它不会退出,我等待那些完成。



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 );
}