Solved

RunDLL command or similar to END TASK a stubborn program?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

22 Experts available now in Live!

Get 1:1 Help Now