Articles   Members Online:
-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 an application without any confirmation 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
18-Sep-03
Category
System
Language
Delphi 5.x
Views
151
User Rating
10
# Votes
1
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

How to kill an application without any confirmation 

Answer:

The following code searches for Notepad, and kills it - no questions asked. Use

1   WinHwnd := FindWindow(classname, nil);
2   
3   //or
4   
5   WinHwnd := FindWindow(nil, 'window-caption');
6   
7   //with your apps details.
8   
9   procedure TForm1.ButtonClick(Sender: TObject);
10  var
11    ProcessHandle: THandle;
12    WinHwnd: HWND;
13    ProcessID, ExitCode: Integer;
14  begin
15    ProcessID := 0;
16    ExitCode := 0;
17    WinHwnd := FindWindow('NotePad', nil);
18    if not (IsWindow(WinHwnd)) then
19    begin
20      ShowMessage('NotePad not found');
21      exit;
22    end;
23    GetWindowThreadProcessID(WinHwnd, @ProcessID);
24    ProcessHandle := OpenProcess(PROCESS_CREATE_THREAD or PROCESS_VM_OPERATION
25      or PROCESS_VM_WRITE or PROCESS_VM_READ or
26      PROCESS_TERMINATE, False, ProcessID);
27    if (ProcessHandle > 0) then
28    begin
29      GetExitCodeProcess(ProcessHandle, ExitCode);
30      { or  GetExitCodeProcess(ProcessHandle, DWORD(ExitCode)); }
31      TerminateProcess(ProcessHandle, ExitCode);
32      CloseHandle(ProcessHandle);
33    end
34    else
35      ShowMessage('Unable to get proccess Handle');
36  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