Program List

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.
gavarAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CynnaConnect With a Mentor Commented:
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
 
AvonWyssCommented:
Windows NT/2000/XP or WIndows 9x/ME?
0
 
tongaliteCommented:
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
tongaliteCommented:
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
 
CrazyOneConnect With a Mentor Commented:
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
 
gavarAuthor Commented:
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
 
gavarAuthor Commented:
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
 
gavarAuthor Commented:
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
 
pnh73Commented:
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
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.