Re: Re: How do I kill a process


Posted by Thomas Knauff on February 16, 2001 at 15:51:58:

In Reply to: Re: How do I kill a process posted by Slimdog on September 15, 2000 at 17:19:15:

Hi ou there,

I can try what I want
FSnapshotHandle := CreateToolhelp32Snapshot
(TH32CS_SNAPPROCESS, 0);
will always return only a "0" and therefore process32first will not find anything....

I could not get it running (using delphi 5)

is there a notfoundyet compiler-switch to toggle ?

thomas

: Hi-Ho,
: if you know the name of the exe, you can use this:

: ---------SNIP---------

: uses
: Tlhelp32, Windows, SysUtils;
: 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;

: ---------SNIP----------

: CU
: Slimdog




Related Articles and Replies: