Solved

Program List

Posted on 2002-05-26
9
349 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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