Solved

RunDLL command or similar to END TASK a stubborn program?

Posted on 2001-07-24
5
369 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now