Solved

RunDLL command or similar to END TASK a stubborn program?

Posted on 2001-07-24
5
383 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

691 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