Solved

WINEXEC - Wait for completion..

Posted on 1997-05-16
1
2,744 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
drawing animated level bar based on numbers 3 121
How to build JSON File in Delphi 6 3 95
Delphi: making a BW image transparent 10 137
How to make Sign in, using Clientdataset? 1 43
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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