Вниз
Скачать: CL | DM;

Контроль внешнего процесса   Найти похожие ветки 

 
Vasily_ ©   (2003-03-17 21:31) [0]

Как проконролировать завершение внешней программы, запущеной из моего приложения?
Заранее благодарен за ответ, жедательно с примером.


 
Юрий Зотов ©   (2003-03-17 21:49) [1]

implementation

uses
Unit2;

procedure TForm1.Button1Click(Sender: TObject);
begin
with TMyThread.Create(False) do
begin
CommandLine := "Notepad.exe AutoExec.bat";
WorkingDirectory := "C:\";
OnTerminate := ThreadFinished
end
end;

procedure TForm1.ThreadFinished(Sender: TObject);
begin
with TMyThread(Sender) do
begin
Caption := IntToStr(ExitCode);
Free
end
end;

=========================================================

unit Unit2;

type
TMyThread = class(TThread)
private
FCommandLine: string;
FWorkingDirectory: string;
FExitCode: DWORD;
protected
procedure Execute; override;
public
property CommandLine: string read FCommandLine write FCommandLine;
property WorkingDirectory: string read FWorkingDirectory write FWorkingDirectory;
property ExitCode: DWORD read FExitCode;
end;

implementation

procedure TMyThread.Execute;
var
SI: TStartupInfo;
PI: TProcessInformation;
begin
ZeroMemory(@SI, SizeOf(SI));
SI.cb := SizeOf(SI);
if CreateProcess(nil, PChar(FCommandLine), nil, nil, False, 0, nil, PChar(FWorkingDirectory), SI, PI) then
begin
CloseHandle(PI.hThread);
while not Terminated and (WaitForSingleObject(PI.hProcess, 1000) = WAIT_TIMEOUT) do;
if Terminated or not GetExitCodeProcess(PI.hProcess, FExitCode) then FExitCode := $FFFFFFFF;
CloseHandle(PI.hProcess)
end
else FExitCode := GetLastError
end;


Запуск из основного потока:




Страницы: 1 вся ветка

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.016 c
3-87878
ddenisv
2003-03-11 13:24
2003.03.27
DBGridEh - как делать следующее?


4-88312
tga
2003-01-30 07:15
2003.03.27
Как получить список локальных дисков?


1-87912
hawkins
2003-03-14 09:01
2003.03.27
Есть ли компонент, такой же как TLabel, но многострочный?


9-87768
JB
2002-10-28 12:05
2003.03.27
Всё те же спрайты................................................


14-88205
vendoor
2003-03-11 14:00
2003.03.27
Помогите найти SUIPACK + CRACK к нему




   Наверх