List Active Apps in TreeView

Posted on 2001-02-20
Last Modified: 2008-03-17
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);

Question by:SwOoPe
LVL 20

Expert Comment

ID: 5862533
For which OS do you need it (win9x family or winNT family or both)? And which Delphi version are use using?
LVL 27

Expert Comment

ID: 5862631
listening . . . (seems to be one of my older samples(nice:-), works only for the win9x-family)

madshi go on, its your domain

meikl ;-)

Expert Comment

ID: 5863665
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.


Author Comment

ID: 5863886
Well it would be nice if it workt under all OS.

Im using Delphi 4 c/s.

LVL 20

Accepted Solution

Madshi earned 300 total points
ID: 5864367
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.

Author Comment

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

LVL 20

Expert Comment

ID: 5883019
It can be downloaded here:

(sorry for the delay in commenting)
LVL 27

Expert Comment

by:Asta Cu
ID: 6932024
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:



Expert Comment

ID: 9344198
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.
LVL 14

Expert Comment

ID: 9470399
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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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