Go Premium for a chance to win a PS4. Enter to Win


List Active Apps in TreeView

Posted on 2001-02-20
Medium Priority
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
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.


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 1200 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 http://www.microsoft.com/net. (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  http://www.microsoft.com/net/

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:  http://www.experts-exchange.com/commspt/Q.20277028.html



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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

824 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