Solved

RunDLL command or similar to END TASK a stubborn program?

Posted on 2001-07-24
5
377 Views
Last Modified: 2010-04-06
I am trying to kill a stubborn program and need a simple routine (or program I can launch) that will kill a process based on either its handle or title (doesn't matter which).  

I'm not good with Windows API programming, but I have tried sending WM_QUIT, etc, and TerminateProcess and TerminateThread to no avail.  The only way I can kill this particular program is to CTRL-ALT-DEL End Task (it pops up another End Task box after a few seconds).  Is there a RunDLL command or similar I can launch?
0
Comment
Question by:jsexton
  • 2
  • 2
5 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 6316125
hi,
just change the caption to your apps caption ,either in the code or read it from a edit box :

procedure CloseApp(h : HWND);
Var pID,hProcess:DWord;
Begin
GetWindowThreadProcessId(h,@pID);
hProcess:=OpenProcess(PROCESS_TERMINATE,TRUE,pID);
TerminateProcess(hProcess,1);
End;

//TO kill process IMEDIATLY
procedure TForm1.Button1Click(Sender: TObject);
Var
 h : Thandle;
begin
 h := FindWindow(nil,'Untitled - Notepad');
 If h <> 0 Then
CloseApp(h);
 end;

// to close nicely ,give it chance to say do you
//want to save changes to user as in closing
// notepad with some text in it

procedure TForm1.Button2Click(Sender: TObject);
Var
 h : Thandle;
begin
 h := FindWindow(nil,'Untitled - Notepad');
 If h <> 0 Then
  PostMessage(h, WM_CLOSE,0,0);
 end;
0
 
LVL 20

Expert Comment

by:Madshi
ID: 6316160
AAAHHH, someone forgot to close the handle again...  :-(

Yep, TerminateProcess is the way to go if you want to kill like Ctrl+Alt+Del does.

Regards, Madshi...  :-)
0
 
LVL 17

Expert Comment

by:inthe
ID: 6316187
oops so i did forgot a Closehandle(:-)

i would try the button2 method first though cause its a bit more nicer than TerminateProcess method.
0
 

Author Comment

by:jsexton
ID: 6319705
I'll give it a whirl tonight.  Thanks!
0
 

Author Comment

by:jsexton
ID: 6320540
Actually, the PostMessage works beautifully, but I'll remember TerminateProcess() just in case.  Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Internet Explorer View Settings Question 15 122
Create a path if not exists 7 105
Graphics32 under Delphi 10.1 Berlin 2 123
Drag & Drop... Data from one grid to another 2 47
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question