Solved

CanClose

Posted on 2000-03-02
9
144 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
ID: 2578267
Use:

Application.Terminate;


Regards,

Epsylon.
0
 
LVL 1

Author Comment

by:sageryd
ID: 2578284
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
ID: 2578295
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
ID: 2578327
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:sageryd
ID: 2578354
Thanx!
0
 
LVL 13

Expert Comment

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

Expert Comment

by:Epsylon
ID: 2578369
:o)
0
 
LVL 17

Expert Comment

by:inthe
ID: 2578372
:o)
0
 
LVL 1

Author Comment

by:sageryd
ID: 2579332
;o)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

895 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

13 Experts available now in Live!

Get 1:1 Help Now