problem with closing set of programmes ?

Hi guys
I use winexec to run another program2 by my program
and use killtask to close this program2
===============================
function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,
FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,
FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
=============================
but some programmes2 ( which I run them by my program)
run another programmes3 at the same time they(which I run them by my program) begin run .
======
- my program run program2
- program2 run programmes3
======
so killtask close only the program2 which I run .
and programmes3 which run with this program2 still working.

I may have made a mistake in my code. I don't have time right now but i will in a bit. But the parent processID (FProcessEntry32.th32ParentProcessID) of any app which equals the ProcessID of program 2 (FProcessEntry32.th32ProcessID) will have been created by program 2
Fiddle around with the code.

I have exams on (see my profile) at the moment so i won't be able to give you a detailed post until when i have some good spare time. I still believe that the code i posted should work. Maybe where i had terminateprocess(...) replace with:

while integer(ContinueLoop) <> 0 do
begin
//Change below to the name of program2
if FProcessEntry32.th32ParentProcessID=FindPID('Program2.exe') then //if equal then terminate it
begin
killtask(FProcessEntry32.szExeFile);
end;
ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);

I want all programs to be closed that have been opened by program2 and by another program and by me in a direct way(means: all programmes which run after a certain time with no care about who run them) after a certain time and allow others that have been opened prior to this time to remain

procedure tform1.find_new_processes_created_after_time ;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOLEAN;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
X,count:integer;
begin
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
x:=-1; //reset
count:=x; //reset
while integer(ContinueLoop) <> 0 do
begin
inc(x); //increment x
try
if FProcessEntry32.szExeFile<>processstr[x] then
begin
inc(count) //doesnt equal item then increment count
end;
except
end;
if count>-1 then //it is a new process if >=0
begin
if now>strtodatetime(edit1.text) then //if it is newer than time
begin
killtask(FProcessEntry32.szExeFile) ; //kill it
// or use this if you only want to kill that specific one. If there are two notepad.exes for
//example they would both be closed with killtask whereas this wont:
// TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID), 0))

When a new process is opened and the time period is not up then you need to add it to the "before time is up" list

where i have :

if now>strtodatetime(edit1.text) then //if it is newer than time
begin
killtask(FProcessEntry32.szExeFile) ; //kill it
// or use this if you only want to kill that specific one. If there are two notepad.exes for
//example they would both be closed with killtask whereas this wont:
// TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID), 0))

end;

maybe have:

if now>strtodatetime(edit1.text) then //if it is newer than time
begin
killtask(FProcessEntry32.szExeFile) ; //kill it
// or use this if you only want to kill that specific one. If there are two notepad.exes for
//example they would both be closed with killtask whereas this wont:
// TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID), 0))

Introduction
The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work. Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…

Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…