Solved

Terminating a certain program/process by it's title

Posted on 1997-10-30
4
145 Views
Last Modified: 2010-04-04
Hello people,

I have written a program wich shuts down a win95 pc
using delphi. i use the function exitwindowsex
i do a forced shutdown (no questions) just shutdown.

but when i do this i get an GPF when a certain program is active, 'it is a client program from take control of that pc' and now for the question.

i want to 'terminate' this program, before the ExitWindowsEx
in only know it's title "PC-Duo Client". when i do a CTRL-ALT-DEL and then terminate that task everything works fine.

Thanx in advance,

Mories
0
Comment
Question by:mories
[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
4 Comments
 
LVL 3

Accepted Solution

by:
Pegasus100397 earned 50 total points
ID: 1349179
Mories,

Use the ExitProcess() or TerminateProcess() API functions. They will do what you are looking to accomplish. With TerminateProcess you will first have to get the window handle of the program (PC-Duo Client). ExitProcess is prefered (clean shutdown of the task) and TerminateProcess is the sledgehammer approach.

Good luck with your project!
Pegasus
0
 
LVL 1

Author Comment

by:mories
ID: 1349180
hello pegasus

can you give me an example how to do this ?

i tried this...

procedure TForm1.Button1Click(Sender: TObject);
var
  h : Thandle;
begin
  h := FindWindow('ExploreWClass','Verkenner - (C:)');
  ShowWindow(h,SW_MAXIMIZE);
  TerminateProcess(h,0);
end;

the showWindow function works, but i cannot get the terminateProcess fuction to work.
do i need to do something else

thanx again

0
 
LVL 3

Expert Comment

by:Pegasus100397
ID: 1349181
Mories,

Before we use TerminateProcess and / or ExitProcess, let's try the "recommended" approach to the orderly shutdown. Try this (works for notepad!) :)

procedure TForm1.Button1Click(Sender: TObject);
var
h : Thandle;
begin
h := FindWindow('notepad','Untitled - Notepad');
If h > 0 then
   Begin
     ShowWindow(h,SW_MAXIMIZE);
     SendMessage(h, WM_CLOSE,0,0); {Tell the app to shut down}
   end
else
   Showmessage('Window was not found to terminate');
end;


Regards,
Pegasus
0
 
LVL 1

Author Comment

by:mories
ID: 1349182
Thanx, last solution works great for my pc-duo program !!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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