Solved

WINEXEC - Wait for completion..

Posted on 1997-05-16
1
2,658 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This video discusses moving either the default database or any database to a new volume.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now