Solved

Terminating a certain program/process by it's title

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to fill array with TArray.Create? 14 90
Newbie Thread Programming 1 154
FMX enumerated colours 2 101
Can Viruses spread while transferring Binary data with Winsock 2 77
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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

810 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