Solved

Terminating a certain program/process by it's title

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

707 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

10 Experts available now in Live!

Get 1:1 Help Now