Solved

Program List

Posted on 2002-05-26
9
346 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
Comment Utility
Windows NT/2000/XP or WIndows 9x/ME?
0
 
LVL 3

Expert Comment

by:tongalite
Comment Utility
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
Comment Utility
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
 
LVL 44

Assisted Solution

by:CrazyOne
CrazyOne earned 175 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:gavar
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

728 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now