Solved

CanClose

Posted on 2000-03-02
9
141 Views
Last Modified: 2012-05-04
How can I close a Delphi-made program which has the CanClose property set to False? (might add: another program, not my own)

CloseWindow(hWnd); doesn't work!

Neither does DestroyWindow(hWnd);!

Plz help!

johan
0
Comment
Question by:sageryd
  • 4
  • 3
  • 2
9 Comments
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
Use:

Application.Terminate;


Regards,

Epsylon.
0
 
LVL 1

Author Comment

by:sageryd
Comment Utility
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
 
LVL 1

Author Comment

by:sageryd
Comment Utility
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
Comment Utility
Hi
if you can find out the class name of the window then you can do:

procedure TForm1.Button1Click(Sender: TObject);
var
h : thandle;
ProcessID,cpid : Cardinal;
begin
h := findwindow('classnameof window',nil);
ProcessID := GetWindowThreadProcessID(h,@cpid);
TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,cpid),1);
end;


or if you cant get the class name use madshis enumstuff unit to do it:

http://nettrash.com/users/madshi/

then can do:

uses Enumstuff;

Procedure Killapp(exeFile: string);
var pl : TProcessList;
    i1 : integer;
     h : thandle;
begin
  pl:=GetProcessList;
  for i1:=0 to high(pl) do
    if CompareText(ExtractFileName(pl[i1].name),ExtractFileName(exeFile))=0 then begin
 h := openprocess(PROCESS_TERMINATE,false,pl[i1].pid);
   TerminateProcess(h,0);
   closehandle(h);
      exit;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
killapp('notepad.exe')
end;


Regards Barry
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:sageryd
Comment Utility
Thanx!
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
I think TerminateProcess will do but I don't know how to find the right ProcessID.
0
 
LVL 13

Expert Comment

by:Epsylon
Comment Utility
:o)
0
 
LVL 17

Expert Comment

by:inthe
Comment Utility
:o)
0
 
LVL 1

Author Comment

by:sageryd
Comment Utility
;o)
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi XE7 Rest Client 2 172
Best Firemonkey component pack 1 73
oracle global variables 4 51
Magic Software info 18 101
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

9 Experts available now in Live!

Get 1:1 Help Now