Como executar um programa e aguardar ele fechar??
Olá pessoal,
Estou precisando executar um programa e esperar ele fechar para meu código continuar.
Tipo qd faz um ShowModal.
Já utilizei WinExec e ShellExecute e não consegui fazer isso. O arquivo é um arquivo Exe normal.
Existe algum parametro que passo ou função q faça isso?
Obrigado.
Estou precisando executar um programa e esperar ele fechar para meu código continuar.
Tipo qd faz um ShowModal.
Já utilizei WinExec e ShellExecute e não consegui fazer isso. O arquivo é um arquivo Exe normal.
Existe algum parametro que passo ou função q faça isso?
Obrigado.
Yallebr
Curtidas 0
Respostas
Yallebr
19/05/2005
Achei um codigo q faz isso
var proc_info: TProcessInformation; startinfo: TStartupInfo; ExitCode: longword; begin // Initialize the structures FillChar(proc_info, sizeof(TProcessInformation), 0); FillChar(startinfo, sizeof(TStartupInfo), 0); startinfo.cb := sizeof(TStartupInfo); // Attempts to create the process if CreateProcess(´c:\windows\notepad.exe´, nil, nil, nil, false, NORMAL_PRIORITY_CLASS, nil, nil, startinfo, proc_info) <> False then begin // The process has been successfully created // No let´s wait till it ends... WaitForSingleObject(proc_info.hProcess, INFINITE); // Process has finished. Now we should close it. GetExitCodeProcess(proc_info.hProcess, ExitCode); // Optional CloseHandle(proc_info.hThread); CloseHandle(proc_info.hProcess); Application.MessageBox( PChar(Format(´Notepad finished! (Exit code=¬d)´, [ExitCode])), ´Info´, MB_ICONINFORMATION); end else begin // Failure creating the process Application.MessageBox(´Couldn´´t execute the ´ + ´application´, ´Error´, MB_ICONEXCLAMATION); end;//if
GOSTEI 0