如果用system()可以实现dos程序,但是对于类似setup.exe这种安装文件就不行了。
例如:
system("setup1.exe")
system("setup2.exe")
这样的话,就会同时弹出这两个程序运行,能否控制一个程序一个程序的运行,当
一个程序运行完成以后才运行另外的。
找了很多方法,都不行。
有什么好方法?
例如:
system("setup1.exe")
system("setup2.exe")
这样的话,就会同时弹出这两个程序运行,能否控制一个程序一个程序的运行,当
一个程序运行完成以后才运行另外的。
找了很多方法,都不行。
有什么好方法?
STARTUPINFO si;
si.cb = sizeof(STARTUPINFO);
si.lpReserved = NULL;
si.lpDesktop = NULL;
si.lpTitle = NULL;
si.dwFlags = 0;
si.cbReserved2 = 0;
si.lpReserved2 = NULL;
BOOL bres = CreateProcess(NULL,"test a.txt b.txt",NULL,NULL,false,
NORMAL_PRIORITY_CLASS,
NULL,NULL,&si,&pi);
if(bres==false)
{
AfxMessageBox("CreateProcess failed");
}
else
{
CloseHandle(pi.hThread);
DWORD dwret=WaitForSingleObject(pi.hProcess, 1000*30);
switch(dwret)
{
case WAIT_OBJECT_0:
DWORD dwexitcode;
bres = GetExitCodeProcess(pi.hProcess,&dwexitcode);
TCHAR exitmsgbuf[1024];
if(bres)
{
wsprintf(exitmsgbuf,"exit code:%d",dwexitcode);
}
else
wsprintf(exitmsgbuf,"exit code failed to return");
WaitForSingleObject(pi.hProcess, 1000*30);的等待时间改为无限即可,第一个程序setup1.exe完成后,创建setup2.exe,依此类推。
CreateProcess(NULL,"test a.txt b.txt",NULL,NULL,false,
dwret=WaitForSingleObject(pi.hProcess, 1000*30);