?
Solved

Program List

Posted on 2002-05-26
9
Medium Priority
?
360 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 44

Assisted Solution

by:CrazyOne
CrazyOne earned 700 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 700 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

Industry Leaders: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

770 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