Solved

Program List

Posted on 2002-05-26
9
348 Views
Last Modified: 2011-09-20
I need a bit of working source code that will give me a list of programs running, identical to the "Start Bar", bonus points if It will give me the icon for each program.
0
Comment
Question by:gavar
9 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 7035680
Windows NT/2000/XP or WIndows 9x/ME?
0
 
LVL 3

Expert Comment

by:tongalite
ID: 7035711
Hi,
This will do exactly what you ask and a lot more besides :)

This is the download zip:

http://www.cosy.sbg.ac.at/~mliedl/sources/win/Taskview.zip

It lists all the running tasks. Full source code and demo exe supplied
Check it out.
Have fun
T.
0
 
LVL 3

Expert Comment

by:tongalite
ID: 7035716
Oops!
I may have misunderstood your question :-(
Do you mean like the START MENU?

with a list of programs (and icons)when you click the start button?

T.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 44

Assisted Solution

by:CrazyOne
CrazyOne earned 175 total points
ID: 7036481
Don't remember where I got this from I suspect it was here at EE.

unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.DFM}
Uses
 Psapi;

{procedure CreateWin9xProcessList(List : TStringList);
var
 hSnapShot : THandle;
 ProcInfo : TProcessEntry32;
begin
 if List = nil then Exit;
 hSnapShot := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
 if (hSnapShot <> THandle(-1)) then
 begin
   ProcInfo.dwSize := sizeof(ProcInfo);
   if (Process32First(hSnapshot, ProcInfo)) then
   begin
    List.Add( ProcInfo.szExeFile);
    while (Process32Next(hSnapShot, ProcInfo)) do
     List.Add(ProcInfo.szExeFile);
   end;
   CloseHandle(hSnapShot);
 end;
end;}

procedure CreateWinNTProcessList(List : TStringList);
var
 cb : DWORD;
 dwPID : array [0..1023] of DWORD;
 chModName : array [0..300] of char;
 i, iCount: integer;
 hMod : HMODULE;
 hPrcss : THandle;

begin

 if List = nil then Exit;
 EnumProcesses(@dwPID, sizeof(dwPID), cb);
 iCount := cb div sizeof(DWORD);
 for I := 0 to iCount-1 do
 begin
   hPrcss := OpenProcess(PROCESS_QUERY_INFORMATION
   or PROCESS_VM_READ,  false, dwPID[I]);
   if (hPrcss <> 0) then
   begin
     EnumProcessModules(hPrcss, @hMod, sizeof(hMod), cb);
     GetModuleFilenameEx(hPrcss,hMod,ModuleName,sizeof(ModuleName));
     List.Add(ModuleName);
     CloseHandle(hPrcss);
   end;
 end;
end;

procedure GetProcessList(Var List : TStringList);
var ovi : TOSVersionInfo;
begin
 if List = nil then Exit;
 ovi.dwOSVersionInfoSize := sizeof(TOSVersionInfo);
 GetVersionEx(ovi);
 case ovi.dwPlatformId of
   //VER_PLATFORM_WIN32_WINDOWS : CreateWin9xProcessList(List);
   VER_PLATFORM_WIN32_NT : CreateWinNTProcessList(List);
 end
end;

function EXE_Running(FileName : String; fullpath : boolean) : boolean;
var
 i : integer;
 MyProcList : TStringList;
begin
MyProcList := TStringList.Create;
try
  GetProcessList(MyProcList);
  result := false;
  if MyProcList = nil then Exit;
   for i := 0 to MyProcList.Count - 1 do
   begin
     if not fullpath then
     begin
      if CompareText(ExtractFileName(MyProcList.Strings[i]),FileName) = 0 then result := true
     end else
      if CompareText(MyProcList.Strings[i],FileName) = 0 then result := true;
    if result then break;
   end;
 finally
  MyProcList.Free;
end;
end;


// Example 1: Is a Exe-File running ?
procedure TForm1.Button1Click(Sender: TObject);
begin
if EXE_Running('notepad.exe',false) then
   ShowMessage('EXE is running')
else
   ShowMessage('EXE is not running');
end;


// Example 2: List running Exe-Files
procedure TForm1.Button3Click(Sender: TObject);
var
 i : integer;
 MyProcList : TStringList;
begin
MyProcList := TStringList.Create;
try
  GetProcessList(MyProcList);
  if MyProcList = nil then Exit;
   for i := 0 to MyProcList.Count - 1 do
     ListBox1.items.add(MyProcList.Strings[i]);
finally
  MyProcList.Free;
end;
end;

//And if you wanted to kill and app you could do something like:
procedure KillApp(title : string);
var h : HWND;

begin
h:=FindWindow(nil,@(title)[1]);
if h<>0 then
       begin
       SendMessage(h,WM_CLOSE,0,0);
       Showmessage('App terminated.')
       end
       else
       Showmessage('failed kill app.')
end;

end.


The Crazy One
0
 

Author Comment

by:gavar
ID: 7054793
tongalite,

That link seems to be wrong.

what I need is a list of just the programs running, like what is just to the left of the start button(Win 9X), and a way I can minimize maximize & close them.

I will give more points for working code!
0
 

Author Comment

by:gavar
ID: 7054817
CrazyOne,

I tried that source and it won't let me compile it,
Undeclared Identifier "TProcessEntry32"
but it definately looks promising. Do you know how to get the Icon of an EXE program that is running?
0
 
LVL 7

Accepted Solution

by:
Cynna earned 175 total points
ID: 7061886
gavar,

> Undeclared Identifier "TProcessEntry32"

Add 'Tlhelp32' to your uses list.


>  Do you know how to get the Icon of an EXE program that  is running?

ExtractIcon(hInstance, ExeFileName, 0);

 Example:
------------

1. Add Button and Image on a form
2. Add 'ShellApi' to your uses list
3. Write:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Image1.Picture.Icon.Handle:=ExtractIcon(hInstance, 'C:\WINDOWS\regedit.exe', 0);
end;
0
 

Author Comment

by:gavar
ID: 7410300
You know how when you launch an application a button for that application is put on the taskbar. (too the right of the start button.) I need to be able to recreate that list of programs, adentical to what would show up on that bar.

0
 
LVL 1

Expert Comment

by:pnh73
ID: 9006868
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between Cynna and CrazyOne

Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Paul (pnh73)
EE Cleanup Volunteer
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Firemonkey Need Sample for Online Shopping Example. 2 145
Magic Software info 18 132
how to change, disabled button color FMX ? 1 33
Firemonkey allowing RTL on android 6 33
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…
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 Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

831 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