• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

CanClose

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
sageryd
Asked:
sageryd
  • 4
  • 3
  • 2
1 Solution
 
EpsylonCommented:
Use:

Application.Terminate;


Regards,

Epsylon.
0
 
sagerydAuthor Commented:
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
 
sagerydAuthor Commented:
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
Independent Software Vendors: 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!

 
intheCommented:
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
 
sagerydAuthor Commented:
Thanx!
0
 
EpsylonCommented:
I think TerminateProcess will do but I don't know how to find the right ProcessID.
0
 
EpsylonCommented:
:o)
0
 
intheCommented:
:o)
0
 
sagerydAuthor Commented:
;o)
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!

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now