List Active Apps in TreeView

I need some help with this code. I ned a button that calls the TerminateProcess and kills the selected program in the TreeView. If posible to list the .dll & .ocx files that belongs to the selected program instead of the windows it contains. And maybe show the real icons that belongs to a surtin program!

unit UP;


 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
 StdCtrls, tlhelp32, ComCtrls, ImgList;

 TForm1 = class(TForm)
   Button1: TButton;
   TreeView1: TTreeView;
    Edit1: TEdit;
    Button2: TButton;
    ImageList1: TImageList;
   procedure Button1Click(Sender: TObject);
   procedure TreeView1Click(Sender: TObject);
   procedure TreeView1Change(Sender: TObject; Node: TTreeNode);
   Procedure GetThreads(ProcessID : DWord);
   Procedure GetProcesslist;
   { Private-Deklarationen }
   { Public-Deklarationen }

 Form1: TForm1;


{$R *.DFM}

 WNode2: TTreeNode = Nil; {intern Global defined for multiple use}
 WNode : TTreeNode = Nil; {intern Global defined for multiple use}
 WName : Array[0..100] of char;
 TheWinHandle : THandle = 0; {intern Global defined for intern global Access}

Function TWCallBack(H : THandle; V : Longint) : longBool; stdcall;
 if GetParent(H) = 0 then
   WNode2 := Form1.TreeView1.Items.AddChild(WNode,StrPas(@WName[0]));
   WNode2.Data := Ptr(H); {Store the Handle in the DataOption}
 Result := True;

Procedure TForm1.GetThreads(ProcessID : DWord);
 ThreadEntry32 : TThreadEntry32; {Defined in TlHelp32}
 TLHandle : THandle;
 TLHandle := CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
 if Thread32First(TLHandle,ThreadEntry32) then
   if ThreadEntry32.th32OwnerProcessID = ProcessID then
   while Thread32Next(TLHandle,ThreadEntry32) do
     if ThreadEntry32.th32OwnerProcessID = ProcessID then

Procedure TForm1.GetProcesslist;
 PLHandle : Thandle;
 ProcessEntry32 : TProcessEntry32; {Defined in TlHelp32}
 PLHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 if Process32First(PLHandle,ProcessEntry32) then
   Wnode := TreeView1.Items.Add(Nil,strPas(@ProcessEntry32.szExeFile[0]));
   while Process32Next(PLHandle,ProcessEntry32) do
     Wnode := TreeView1.Items.Add(Nil,strPas(@ProcessEntry32.szExeFile[0]));

Procedure CleanUpTree(Nodes : TTreeNodes);
 {CleanUp Windows without Text (most Controls)}
 WNode := Nodes.GetFirstNode;
 While WNode <> Nil do
   If WNode.Text = '' then
     WNode2 := WNode.Getnext;
     WNode := WNode2;
     WNode := WNode.GetNext;


procedure TForm1.Button1Click(Sender: TObject);

procedure TForm1.TreeView1Click(Sender: TObject);
 If Treeview1.selected.Level = 1 then {Level 1 entrys Only}
   TheWinHandle := THandle(Treeview1.selected.Data); {Get the Handle from the DataOption}
   { Do Something with the Handle, must not be in this Procedure }
   edit1.text := IntToStr(TheWinHandle);

procedure TForm1.TreeView1Change(Sender: TObject; Node: TTreeNode);

Who is Participating?
MadshiConnect With a Mentor Commented:
The TerminateProcess part is no big problem. Getting it to run in this form under NT is not too difficult, either (by using my free unit "enumStuff.pas"). But getting the modules (= dlls + ocxs) of the other processes is a bit more complicated. For that purpose you need for NT either Microsoft's PsApi.dll (and then you need to distribute it with your application) or you can use my package "madKernel" (free for non-commercial usage). If you're interested, I can do what you want at the weekend - but using "madKernel". What do you think?

Regards, Madshi.
For which OS do you need it (win9x family or winNT family or both)? And which Delphi version are use using?
listening . . . (seems to be one of my older samples(nice:-), works only for the win9x-family)

madshi go on, its your domain

meikl ;-)
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

SwOoPeAuthor Commented:
Well it would be nice if it workt under all OS.

Im using Delphi 4 c/s.

SwOoPeAuthor Commented:
I can´t find enumStuff.pas on your web site. Where is it?

It can be downloaded here:

(sorry for the delay in commenting)
Asta CuCommented:
Hopefully you've already been helped with this question, but thought you'd appreciate knowing this.  It would be great if you could bring this question to a conclusion, awarding the experts above who helped you with points or a comment to them on your status today.

WindowsUpdate has new updates for .NET users; Details follow - Microsoft .NET Framework
The .NET Framework is a new feature of Windows. Applications built using the .NET Framework are more reliable and secure. You need to install the .NET Framework only if you have software that requires it.

For more information about the .NET Framework, see (This site is in English.)

System Requirements
The .NET Framework can be installed on the following operating systems:
Windows 98
Windows 98 Second Edition (SE)
Windows Millennium Edition (Windows Me)
Windows NT 4.0® (Workstation or Server) with Service Pack 6.0a
Windows 2000 with the latest service pack installed (Professional, Server, Datacenter Server, or Advanced Server)
Windows XP (Home Edition and Professional)
You must be running Internet Explorer version 5.01 or later for all installations of the .NET Framework.

To install the .NET Framework, your computer must meet or exceed the following software and hardware requirements:

Software requirements for server operating systems:
MDAC 2.6
Hardware requirements:
For computers running only a .NET Framework application, Pentium 90 mHz CPU with 32 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 mHz CPU with 128 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
Recomended software:
MDAC 2.7 is recommended.
Recommended hardware: For computers running only a .NET Framework application, Pentium 90 MHz CPU with 96 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.
For server operating systems, Pentium 133 MHz CPU with 256 MB memory or the minimum CPU and RAM required by the operating system, whichever is higher.

How to use -> Restart your computer to complete the installation. No other action is required to run .NET Framework applications. If you are developing applications using the .NET Framework, you can use the command-line compilers or you can use a development environment, such as Visual Studio .NET, that supports using the .NET Framework.

How to uninstall
To uninstall the .NET Framework: Click Start, point to Settings, and then click Control Panel (In Windows XP, click Start and then click Control Panel.).
Click Add/Remove Programs.
Click Microsoft .NET Framework (English) v1.0.3705 and then click Change/Remove.
More here

The .NET topic is being considered for addition to our All Topics link soon, so this may interest you as well:

EXPERTS POINTS are waiting to be claimed here:


This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.
No comment has been added lately (20 days), so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area for this question:

RECOMMENDATION: Award points to Madshi http:#5864367

Please leave any comments here within 7 days.

-- Please DO NOT accept this comment as an answer ! --


EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.