Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shutting down external applications

Posted on 1999-07-21
6
Medium Priority
?
230 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:phillipf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 400 total points
ID: 1390180
Hi
Either http://www.madshi.com (maybe offline)at the moment. But the mirror http://beam.to/madshi should work.
If you have D4 you can download the enumStuff unit from that homepage of madshi's. There you can call "GetProcessList" to get a dynamic array with the processID and the exefile path of all running processes.
To end a process you should call OpenProcess to get a process handle to that process, then TerminateProcess(processHandle).

Regards Barry
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 1390181
damn Barry, fast anyway ;-)

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,nil);
          PostThreadMessage(TID,WM_QUIT,0,0);
        end;
        Result := True;
      end;

      procedure TForm1.Button1Click(Sender: TObject);
      var Dummy : Longint;
      begin
        Dummy := 0;
        EnumWindows(@TWCallBack,Dummy);
      end;

      end.

meikl
0
 

Author Comment

by:phillipf
ID: 1390182
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.

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:phillipf
ID: 1390183
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.

0
 

Author Comment

by:phillipf
ID: 1390184
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.

0
 
LVL 17

Expert Comment

by:inthe
ID: 1390185
if you know the handle then use this procedure :

procedure KillProcess(window: HWND; timeOut: cardinal);
var pid,ph : THandle;
    c1,c2  : cardinal;
begin
  GetWindowThreadProcessID(window,@pid);
  ph:=OpenProcess(PROCESS_ALL_ACCESS,false,pid);
  if ph<>0 then
    try
      if timeOut>0 then begin
        c1:=GetTickCount;
        PostMessage(window,WM_CLOSE,0,0);
        while (GetTickCount-c1<timeOut) and GetExitCodeProcess(ph,c2) and (c2=STILL_ACTIVE) do begin
          Sleep(10);
          Application.ProcessMessages;
        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

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 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