Solved

Terminating a certain program/process by it's title

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month5 days, 22 hours left to enroll

627 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