Link to home
Start Free TrialLog in
Avatar of peritoX
peritoX

asked on

View & Kill Processes

How to view all windows' running processes (like in windows task manager), and kill any process?
Like place all processes in ListBox and kill the one the user choose...
Thank you
Avatar of tobjectpascal
tobjectpascal

Alright then, New Application. Stick a Button and a Listbox on there

unit ProKiller;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  WindowList: TList;


implementation

{$R *.DFM}


function EnumWindowsProc(wHandle: HWND; lb: TListBox): Bool; stdcall; export;
var
  Title, ClassName: array[0..255] of char;
  ProcessID,CPid: DWord;
begin
  Result := True;
  GetWindowText(wHandle, Title, 255);
  GetClassName(wHandle, ClassName, 255);
  if IsWindowVisible(wHandle) then
   Begin
     GetWindowThreadProcessID(wHandle,@cpid);
     lb.Items.AddObject(string(Title) + '-' + string(ClassName)+' PID '+IntToStr(CPID),Tobject(CPID));
   End;
end;



procedure TForm1.Button1Click(Sender: TObject);
begin
 ListBox1.Clear;
 EnumWindows(@EnumWindowsProc, Integer(Listbox1));
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
Var
 N: Integer;
 CPID: Dword;
begin
 N:=Form1.ListBox1.ItemIndex;
 CPID:=DWord(ListBox1.Items.Objects[N]);
 TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,CPID),1);
end;

end.

Make sure you assign the double click event for the ListBox as i've made it kill the process of whatever you clicked on.
Avatar of peritoX

ASKER

mmm
it didnt show the processes, it showed the applications
I mean it didnt show
msnmsgr.exe
ctfmon.exe
explorer.exe
...

it showed
Form1
Delphi Proramming: View & Kill Processes - Microsoft Internet Explorer

...

one more thing, how to create a new process
Ill add points
 if IsWindowVisible(wHandle) then
   Begin
     GetWindowThreadProcessID(wHandle,@cpid);
     lb.Items.AddObject(string(Title) + '-' + string(ClassName)+' PID '+IntToStr(CPID),Tobject(CPID));
   End;

replace for

     GetWindowThreadProcessID(wHandle,@cpid);
     lb.Items.AddObject(string(Title) + '-' + string(ClassName)+' PID '+IntToStr(CPID),Tobject(CPID));

and you'll see what i mean.


new process, look up CreateProcess.
in other words remove

>> if IsWindowVisible(wHandle) then
   >>Begin
>> End;

remove them 3 lines.

Avatar of peritoX

ASKER

okey....
now I got many many more things, something like

Shell Embedding PID 3784
ComboLBox PID 4004
tooltips_class32 PID 4004

and many more things

I only want exactly what is found in the process window
exact name
explorer.exe
bla bla

can it be done?
hi,

you can use WMI to get the list of processes/services with pid.:
http://www.ciuly.com/delphi/wmi/runningProcesses/index.html
and
http://www.ciuly.com/delphi/wmi/runningServices/index.html
and terminate the process by pid (for example using the solution from here:https://www.experts-exchange.com/questions/20651898/How-To-Kill-A-Process-Running-in-Windows.html)
Avatar of peritoX

ASKER

its not working
a unit is missing
I guess thats the WMI
where can I download the unit???
:D sorry. forgot that not everybody is setting up their delphi for WMI. here is the "how to":
http://www.ciuly.com/delphi/wmi/settingUpWmi/index.html
hi
you can use the jv components you can download theme from
www.Jedi-project.org
there is an example that shoots your goal exactly
best regards
Avatar of peritoX

ASKER

jedi-project.org is not working (The link)
site down?
google sayd http://www.delphi-jedi.org/ maybe they changed they domain.
ASKER CERTIFIED SOLUTION
Avatar of saravananvg
saravananvg
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MR Padmaja

Thanks for that one i was looking for something similar to that, and that wonderful example is what i needed exactly. Shot!

Scay7

 *** peritoX use This example above my post is what you were looking for, POINTS to saravananvg !!! ***
Avatar of peritoX

ASKER

@saravananvg
exactly as I wanted
you've got the points

before I accept can u give me the code for creating New Porcesses
I'll increase 30 points
Thank you
Hello Sir,

  You can use the ShellExecute Function to create  new process.

  check the following example to create a new process.

uses ShellApi;
...
ShellExecute(Handle, 'open', 'c:\Windows\notepad.exe', nil, nil, SW_SHOWNORMAL) ;

with regards,
padmaja.
Avatar of peritoX

ASKER

Thank You
***Points Increased***