unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ShellAPI;

type
TForm1 = class(TForm)
B_execute: TButton;
B_kill: TButton;
procedure FormCreate(Sender: TObject);
procedure B_executeClick(Sender: TObject);
procedure B_killClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
RunProcess: Longint;

implementation
{$R *.DFM}

function ExecNewProcess(ProgramName: String): Longint;
var
StartInfo : TStartupInfo;
ProcInfo : TProcessInformation;
CreateOK : Boolean;
begin
FillChar(StartInfo, SizeOf(TStartupInfo),#0);
FillChar(ProcInfo, SizeOf(TProcessInformation),#0);
StartInfo.cb := SizeOf(TStartupInfo);



if CreateProcess(PChar(ProgramName),nil, nil, nil,false,
//CREATE_NEW_PROCESS_GROUP+NORMAL_PRIORITY_CLASS, nil, nil, StartInfo,
CREATE_NEW_CONSOLE+NORMAL_PRIORITY_CLASS, nil, nil, StartInfo,
ProcInfo)
then
Result := ProcInfo.hProcess
else
Result := 0;
end;

procedure KillProcess(hProcess: Longint);
begin
// ??? process? ?? ?????
if TerminateProcess(hProcess, 0) = FALSE then
ShowMessage('TerminateProcess error !')
else
ShowMessage('TerminateProcess successfully !');
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
RunProcess := 0;
end;

procedure TForm1.B_executeClick(Sender: TObject);
begin
// ???? ??
RunProcess := ExecNewProcess('c:\windows\notepad.exe');

{ ???? ????? ?????? ????? ? ??? ???
if RunProcess <> 0 then
WaitForSingleObject(RunProcess, -1);
}
end;

procedure TForm1.B_killClick(Sender: TObject);
begin
// ?? ???? ???? ???
if RunProcess <> 0 then
begin
KillProcess(RunProcess);
RunProcess := 0;
end;
end;

end.
