unit Unit1;
interface
uses
Winapi.Windows,
Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
Vcl.StdCtrls,
Vcl.ExtCtrls;
type
TForm1 =
class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
edtFilename: TEdit;
Panel3: TPanel;
Panel4: TPanel;
Label2: TLabel;
edtPH: TEdit;
Panel5: TPanel;
Label3: TLabel;
edtTH: TEdit;
Panel6: TPanel;
Label4: TLabel;
edtPI: TEdit;
Panel7: TPanel;
Button1: TButton;
btnTerminate: TButton;
Panel8: TPanel;
Label5: TLabel;
edtTI: TEdit;
procedure Button1Click(Sender: TObject);
procedure btnTerminateClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
ProcessInfo: TProcessInformation;
procedure ResetGUI;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ResetGUI;
begin
edtPH.Text := '
';
edtTH.Text := '
';
edtPI.Text := '
';
edtTI.Text := '
';
btnTerminate.Enabled := False;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
StartUpInfo: TStartUpInfo;
begin
if (
not FileExists(edtFilename.Text))
then
begin
ResetGUI;
Exit;
end;
FillMemory(@StartUpInfo, SizeOf(StartUpInfo), 0);
StartUpInfo.cb := SizeOf(StartUpInfo);
if CreateProcess(
nil, PChar(edtFilename.Text),
nil,
nil, False, NORMAL_PRIORITY_CLASS,
nil,
nil, StartUpInfo, ProcessInfo)
then
begin
edtPH.Text := IntToStr(ProcessInfo.hProcess);
edtTH.Text := IntToStr(ProcessInfo.hThread);
edtPI.Text := IntToStr(ProcessInfo.dwProcessId);
edtTI.Text := IntToStr(ProcessInfo.dwThreadId);
btnTerminate.Enabled := True;
end;
end;
procedure TForm1.btnTerminateClick(Sender: TObject);
begin
if ((ProcessInfo.hProcess <> 0)
and (ProcessInfo.hProcess <> INVALID_HANDLE_VALUE))
then
if TerminateProcess(ProcessInfo.hProcess, 0)
then
begin
if ((ProcessInfo.hProcess <> 0)
and (ProcessInfo.hProcess <> INVALID_HANDLE_VALUE))
then
CloseHandle(ProcessInfo.hProcess);
if ((ProcessInfo.hThread <> 0)
and (ProcessInfo.hThread <> INVALID_HANDLE_VALUE))
then
CloseHandle(ProcessInfo.hThread);
btnTerminate.Enabled := False;
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if ((ProcessInfo.hProcess <> 0)
and (ProcessInfo.hProcess <> INVALID_HANDLE_VALUE))
then
CloseHandle(ProcessInfo.hProcess);
if ((ProcessInfo.hThread <> 0)
and (ProcessInfo.hThread <> INVALID_HANDLE_VALUE))
then
CloseHandle(ProcessInfo.hThread);
end;
end.