Hi experts,
with the help of Delphi 3.0, I would like to start an external program several times.
It is very important for me that this *.exe is launched a second time not before the first process is terminated. In other words: The *.exe should BY NO MEANS be launched
simultanously,but consecutively. How can I find out, if a shelled process is already
terminated?
In Visual Basic, I would do it like this:
Private Sub btnEndCommand_Click()
Dim i%
For i = 0 To File1.ListCount - 1
If File1.Selected(i) = True Then
If Right$(Dir1.path, 1) = "\" Then
Parameter = Dir1.path + File1.filename
Else
Parameter = Dir1.path + "\" + File1.filename
End If
X% = Shell("E:\MYPROGRAM.EXE " + Parameter, 4)
' Modify the path as necessary.
While GetModuleUsage(X%) > 0
' Has Shelled program finished?
z% = DoEvents() ' If not, yield to Windows.
Wend
End If
Next
MsgBox "Shelled application just terminated", 64
File1.Refresh
End Sub
How can this be done with Delphi 3.0 ?
With kind regards
Christian
In Delphi, we do it like this :
uses Wintypes,WinProcs,Toolhelp
Function WinExecAndWait(Path : string; Visibility : word) : word;
var
InstanceID : THandle; PathLen : integer;
begin
{ inplace conversion of a String to a PChar }
PathLen := Length(Path);
Move(Path[1],Path[0],PathL
{ Try to run the application }
InstanceID := WinExec(@Path,Visibility);
if InstanceID < 32 then { a value less than 32 indicates an Exec error }
WinExecAndWait := InstanceID
else begin
Repeat
Application.ProcessMessage
until Application.Terminated or (GetModuleUsage(InstanceID
WinExecAndWait := 32;
end;
end;
Zif.