phillipf
asked on
Shutting down external applications
From a Delphi app, how can I shut down other applications running on the same server. These other applications do not run as services and are not Delphi Apps.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This looks like it will do the trick. I can find the process just fine but I have not been able to terminate the process yet.
I don't suppose you have a small example of this.
I don't suppose you have a small example of this.
ASKER
This looks like it will do the trick. I can find the process just fine but I have not been able to terminate the process yet.
I don't suppose you have a small example of this.
I don't suppose you have a small example of this.
ASKER
This looks like it will do the trick. I can find the process just fine but I have not been able to terminate the process yet.
I don't suppose you have a small example of this.
I don't suppose you have a small example of this.
if you know the handle then use this procedure :
procedure KillProcess(window: HWND; timeOut: cardinal);
var pid,ph : THandle;
c1,c2 : cardinal;
begin
GetWindowThreadProcessID(w indow,@pid );
ph:=OpenProcess(PROCESS_AL L_ACCESS,f alse,pid);
if ph<>0 then
try
if timeOut>0 then begin
c1:=GetTickCount;
PostMessage(window,WM_CLOS E,0,0);
while (GetTickCount-c1<timeOut) and GetExitCodeProcess(ph,c2) and (c2=STILL_ACTIVE) do begin
Sleep(10);
Application.ProcessMessage s;
end;
if (not GetExitCodeProcess(ph,c2)) or (c2=STILL_ACTIVE) then TerminateProcess(ph,0);
end else TerminateProcess(ph,0);
finally CloseHandle(ph) end;
end;
Regards Barry
procedure KillProcess(window: HWND; timeOut: cardinal);
var pid,ph : THandle;
c1,c2 : cardinal;
begin
GetWindowThreadProcessID(w
ph:=OpenProcess(PROCESS_AL
if ph<>0 then
try
if timeOut>0 then begin
c1:=GetTickCount;
PostMessage(window,WM_CLOS
while (GetTickCount-c1<timeOut) and GetExitCodeProcess(ph,c2) and (c2=STILL_ACTIVE) do begin
Sleep(10);
Application.ProcessMessage
end;
if (not GetExitCodeProcess(ph,c2))
end else TerminateProcess(ph,0);
finally CloseHandle(ph) end;
end;
Regards Barry
hi phillipf,
from my paq a unit that kills all processes except itself
if you will kill a specific, then you have to compare
with for example the windowtitle
unit kill_all_u;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
Function TWCallBack(H : THandle; V : Longint) : longBool; stdcall;
var
Form1: TForm1;
implementation
{$R *.DFM}
Function TWCallBack(H : THandle; V : Longint) : longBool; stdcall;
var
i,j : Integer;
canKill : Boolean;
TID : DWord;
begin
CanKill := True;
if H = application.handle then //save this app
CanKill := False
else
For J := 0 to screen.FormCount - 1 do
if screen.Forms[j].Handle = H then
CanKill := False;
if CanKill then
begin
TID := GetWindowThreadProcessId(H
PostThreadMessage(TID,WM_Q
end;
Result := True;
end;
procedure TForm1.Button1Click(Sender
var Dummy : Longint;
begin
Dummy := 0;
EnumWindows(@TWCallBack,Du
end;
end.
meikl