Posted on Leave a comment

Start and kill process in Delphi

[code language=”pascal”]
var
PrIn: TProcessInformation;
StIn: TStartupInfo;
Res: bool;
ProcID, Process: Cardinal;

// start
begin
GetStartupInfo(StIn);
Res := CreateProcess(PChar(‘..\Project1.exe’),
PChar(‘"command line params"’), nil, nil, False, CREATE_NEW_PROCESS_GROUP,
nil, nil, StIn, PrIn);
ProcID := PrIn.hProcess;
Process := PrIn.dwProcessId;
end;

// kill
begin
TerminateProcess(ProcId, 0);
end;
[/code]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.