Solved

WINEXEC - Wait for completion..

Posted on 1997-05-16
1
2,696 Views
Last Modified: 2012-05-04
In the 16 bit world we used to be able to wait for process terminations by calling GetModuleUsage.  Doesn't work in Win32...
How do I wait for a process (that I launched) to complete?  I want to synchronize some launches.  
I have looked at WaitForSingleObject and it doesn't seem to work.  Help.
0
Comment
Question by:icampbe1
1 Comment
 
LVL 3

Accepted Solution

by:
sperling earned 80 total points
ID: 1336364
Use CreateProcess to start the process, and WaitForSingleObject to wait for the process *handle*.


function ExecAndWait (AProgram : STRING) : BOOLEAN;
var
  StartupInfo : TStartupInfo;
  ProcessInfo : TProcessInformation;
begin
  FillChar (StartupInfo, SizeOf(StartupInfo), 0);
  StartupInfo.cb := SizeOf(StartupInfo);
  Result := CreateProcess (
    nil,
    PChar(AProgram),
    nil,
    nil,
    FALSE,
    0,
    nil,
    nil,
    StartupInfo,
    ProcessInfo);
  if Result then begin
    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end;


This function attempts to start the program. If it could not be started, return value will be FALSE. If it was started, the function waits for the process to terminate, and then returns TRUE.

Regards,

Erik.

0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question