I did a search on the net, and look what I found !!
This procedure takes the name of the EXE then kills it.
I am posting as I am SURE others what this too
Cheers, Jeremy Coulter
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;
-----Original Message-----
From: Myles Penlington <[EMAIL PROTECTED]>
To: Multiple recipients of list delphi <[EMAIL PROTECTED]>
Date: Fri, 12 Oct 2001 16:25:38 +1300
Subject: RE: [DUG]: Unconditional Shutdown
> I presume you use either ExitProcess or TerminateProcess, however you
> need
> the process handle for this to work - there is no mention of requiring
> these
> to be called by a process it self.
>
> Myles.
>
>
> -----Original Message-----
> From: vss [mailto:[EMAIL PROTECTED]]
> Sent: Friday, 12 October 2001 4:17 p.m.
> To: Multiple recipients of list delphi
> Subject: [DUG]: Unconditional Shutdown
>
>
> Hi all.
> I have an app. that can only shutdown IF its logged on as an
> administrator, and even then it askes if you are sure etc.
>
> I need to shut the app. down from another app. but if I do SendMessage
> (hwnd, WM_CLOSE, 0, 0) it obviously tells you that only the admin can
> close the app. etc.
>
> Is there a message or method I can use to kill an app. no mater what ?
> i.e. unconditionally like end task in the even manager does ?
>
> I know I can make my own windows message and do it in a procedure,
> thats
> fine in the next verison of the app. but its the ones out there now I
> need to shut down.
>
> Thanks, Jeremy Coulter
>
>
> -----------------------------------------------------------------------
> ----
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
> -----------------------------------------------------------------------
> ----
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
> Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/