Solved

Terminating a certain program/process by it's title

Posted on 1997-10-30
4
144 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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