Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

WINEXEC - Wait for completion..

Posted on 1997-05-16
1
Medium Priority
?
2,833 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 160 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

927 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