[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 394
  • Last Modified:

RunDLL command or similar to END TASK a stubborn program?

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
jsexton
Asked:
jsexton
  • 2
  • 2
1 Solution
 
intheCommented:
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
 
MadshiCommented:
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
 
intheCommented:
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
 
jsextonAuthor Commented:
I'll give it a whirl tonight.  Thanks!
0
 
jsextonAuthor Commented:
Actually, the PostMessage works beautifully, but I'll remember TerminateProcess() just in case.  Thanks!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now