SwOoPe
asked on
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;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, tlhelp32, ComCtrls, ImgList;
type
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);
private
Procedure GetThreads(ProcessID : DWord);
Procedure GetProcesslist;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Var
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;
begin
if GetParent(H) = 0 then
begin
GetwindowText(H,@WName[0], 100);
WNode2 := Form1.TreeView1.Items.AddC hild(WNode ,StrPas(@W Name[0]));
WNode2.Data := Ptr(H); {Store the Handle in the DataOption}
end;
Result := True;
end;
Procedure TForm1.GetThreads(ProcessI D : DWord);
var
ThreadEntry32 : TThreadEntry32; {Defined in TlHelp32}
TLHandle : THandle;
begin
TLHandle := CreateToolhelp32Snapshot(T H32CS_SNAP THREAD, 0);
if Thread32First(TLHandle,Thr eadEntry32 ) then
begin
if ThreadEntry32.th32OwnerPro cessID = ProcessID then
EnumThreadWindows(ThreadEn try32.th32 ThreadID,@ TWCallBack ,0);
while Thread32Next(TLHandle,Thre adEntry32) do
if ThreadEntry32.th32OwnerPro cessID = ProcessID then
EnumThreadWindows(ThreadEn try32.th32 ThreadID,@ TWCallBack ,0);
end;
CloseHandle(TLHandle);
end;
Procedure TForm1.GetProcesslist;
var
PLHandle : Thandle;
ProcessEntry32 : TProcessEntry32; {Defined in TlHelp32}
begin
PLHandle := CreateToolhelp32Snapshot(T H32CS_SNAP PROCESS, 0);
if Process32First(PLHandle,Pr ocessEntry 32) then
begin
Wnode := TreeView1.Items.Add(Nil,st rPas(@Proc essEntry32 .szExeFile [0]));
GetThreads(ProcessEntry32. th32Proces sID);
while Process32Next(PLHandle,Pro cessEntry3 2) do
begin
Wnode := TreeView1.Items.Add(Nil,st rPas(@Proc essEntry32 .szExeFile [0]));
GetThreads(ProcessEntry32. th32Proces sID);
end;
end;
CloseHandle(PLHandle);
end;
Procedure CleanUpTree(Nodes : TTreeNodes);
begin
{CleanUp Windows without Text (most Controls)}
WNode := Nodes.GetFirstNode;
While WNode <> Nil do
begin
If WNode.Text = '' then
begin
WNode2 := WNode.Getnext;
WNode.Delete;
WNode := WNode2;
end
else
WNode := WNode.GetNext;
end;
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Treeview1.Items.Clear;
GetProcessList;
CleanUpTree(TreeView1.Item s);
end;
procedure TForm1.TreeView1Click(Send er: TObject);
begin
If Treeview1.selected.Level = 1 then {Level 1 entrys Only}
begin
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);
end;
end;
procedure TForm1.TreeView1Change(Sen der: TObject; Node: TTreeNode);
begin
TreeView1Click(Self);
end;
end.
unit UP;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, tlhelp32, ComCtrls, ImgList;
type
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);
private
Procedure GetThreads(ProcessID : DWord);
Procedure GetProcesslist;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
Var
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;
begin
if GetParent(H) = 0 then
begin
GetwindowText(H,@WName[0],
WNode2 := Form1.TreeView1.Items.AddC
WNode2.Data := Ptr(H); {Store the Handle in the DataOption}
end;
Result := True;
end;
Procedure TForm1.GetThreads(ProcessI
var
ThreadEntry32 : TThreadEntry32; {Defined in TlHelp32}
TLHandle : THandle;
begin
TLHandle := CreateToolhelp32Snapshot(T
if Thread32First(TLHandle,Thr
begin
if ThreadEntry32.th32OwnerPro
EnumThreadWindows(ThreadEn
while Thread32Next(TLHandle,Thre
if ThreadEntry32.th32OwnerPro
EnumThreadWindows(ThreadEn
end;
CloseHandle(TLHandle);
end;
Procedure TForm1.GetProcesslist;
var
PLHandle : Thandle;
ProcessEntry32 : TProcessEntry32; {Defined in TlHelp32}
begin
PLHandle := CreateToolhelp32Snapshot(T
if Process32First(PLHandle,Pr
begin
Wnode := TreeView1.Items.Add(Nil,st
GetThreads(ProcessEntry32.
while Process32Next(PLHandle,Pro
begin
Wnode := TreeView1.Items.Add(Nil,st
GetThreads(ProcessEntry32.
end;
end;
CloseHandle(PLHandle);
end;
Procedure CleanUpTree(Nodes : TTreeNodes);
begin
{CleanUp Windows without Text (most Controls)}
WNode := Nodes.GetFirstNode;
While WNode <> Nil do
begin
If WNode.Text = '' then
begin
WNode2 := WNode.Getnext;
WNode.Delete;
WNode := WNode2;
end
else
WNode := WNode.GetNext;
end;
end;
procedure TForm1.Button1Click(Sender
begin
Treeview1.Items.Clear;
GetProcessList;
CleanUpTree(TreeView1.Item
end;
procedure TForm1.TreeView1Click(Send
begin
If Treeview1.selected.Level = 1 then {Level 1 entrys Only}
begin
TheWinHandle := THandle(Treeview1.selected
{ Do Something with the Handle, must not be in this Procedure }
edit1.text := IntToStr(TheWinHandle);
end;
end;
procedure TForm1.TreeView1Change(Sen
begin
TreeView1Click(Self);
end;
end.
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 ;-)
madshi go on, its your domain
meikl ;-)
listening..
ASKER
Well it would be nice if it workt under all OS.
Im using Delphi 4 c/s.
Im using Delphi 4 c/s.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I can´t find enumStuff.pas on your web site. Where is it?
Thanks
Thanks
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:
https://www.experts-exchange.com/newtopics/Q.20276589.html
EXPERTS POINTS are waiting to be claimed here: https://www.experts-exchange.com/commspt/Q.20277028.html
":0)
Asta
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:
https://www.experts-exchange.com/newtopics/Q.20276589.html
EXPERTS POINTS are waiting to be claimed here: https://www.experts-exchange.com/commspt/Q.20277028.html
":0)
Asta
SwOoPe:
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
EXPERTS:
Post your closing recommendations! No comment means you don't care.
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
EXPERTS:
Post your closing recommendations! No comment means you don't care.
SwOoPe,
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 ! --
Thanks,
DragonSlayer
EE Cleanup Volunteer
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 ! --
Thanks,
DragonSlayer
EE Cleanup Volunteer