Articles   Members Online: 3
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to kill a task Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-Oct-02
Category
Shell API
Language
Delphi 2.x
Views
149
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Misha Moellner 

Kill a task using only the .exe name

Answer:

This little function closes all applications with the same  .exe-name. 

  Example: 
1   
2   			KillTask('notepad.exe'); 
3   			KillTask('iexplore.exe');


Working on Win9x/2k, but apparently not on WinNT systems (never tried on my own)

4   uses
5     Tlhelp32, Windows, SysUtils;
6   
7   function KillTask(ExeFileName: string): integer;
8   const
9     PROCESS_TERMINATE = $0001;
10  var
11    ContinueLoop: BOOL;
12    FSnapshotHandle: THandle;
13    FProcessEntry32: TProcessEntry32;
14  begin
15    result := 0;
16  
17    FSnapshotHandle := CreateToolhelp32Snapshot
18      (TH32CS_SNAPPROCESS, 0);
19    FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
20    ContinueLoop := Process32First(FSnapshotHandle,
21      FProcessEntry32);
22  
23    while integer(ContinueLoop) <> 0 do
24    begin
25      if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
26        UpperCase(ExeFileName))
27        or (UpperCase(FProcessEntry32.szExeFile) =
28        UpperCase(ExeFileName))) then
29        Result := Integer(TerminateProcess(OpenProcess(
30          PROCESS_TERMINATE, BOOL(0),
31          FProcessEntry32.th32ProcessID), 0));
32      ContinueLoop := Process32Next(FSnapshotHandle,
33        FProcessEntry32);
34    end;
35  
36    CloseHandle(FSnapshotHandle);
37  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC