Solved

Active Task List

Posted on 1998-05-12
5
157 Views
Last Modified: 2010-04-06
How do I retrieve a list of all running tasks within Windows (like the task manager?).

Stu
0
Comment
Question by:Stuart_Johnson
[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
  • 3
  • 2
5 Comments
 
LVL 5

Accepted Solution

by:
inter earned 80 total points
ID: 1345115
Hi,
This is from one of my previous anwers:

    The following enumaretes more than you want, you can restrict or losen the criteria to display the  memory contents on even window basis. Just change the IF statement in the EnumWindowsProc. To   compile , create a new unit, add A button, A ListBox, assign OnClick event of button to the following   code(Button1Click) then run.

    var
      S : TStringList;

    function EnumWindowsProc(hwnd : HWND ;lParam : longint):boolean;stdcall;
    var
      wn : array[0..255] of char;
      pid: THandle;
      w : string;
    begin
      if hwnd <> 0 then
      begin
        GetWindowThreadProcessId(hwnd, @pid);
        // filter out if this is our application window
        // and all child windows
        if (pid <> GetCurrentProcessId) and (GetParent(hwnd)= 0) then
        begin
          // get the caption
          // or use the commented IF to get application names
          if GetWindowText(hwnd, wn,sizeof(wn)) <> 0 then
    //    if GetModuleFileName(GetWindowLong(hwnd,GWL_HINSTANCE),wn,sizeof(wn)) <> 0 then
          begin{}
            w:= Format('%6d ',[pid])+StrPas(wn);
            S.Add(w);
          end;{}
       end;
        result := true;
      end else result := false;
    end;

    procedure TForm1.Button1Click(Sender: TObject);
    begin
      try
       S := TStringList.Create;
       S.Sorted := true;
       S.Duplicates := dupIgnore;
       ListBox1.Items.Clear;
       S.Clear;
       EnumWindows(@EnumWindowsProc,0);
       ListBox1.Items.AddStrings(S);
      finally
        S.Free;
      end;
    end;

    Bye
    Igor
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345116
inter:

Thanks for the post, however when we tried it we continually got protection errors.  

I had to change the StringList to a TStrings type.  That fixed the protection fault, but there is a problem when we are converting the WN array to the string.  Although the array contains information, it is not being converted to a string.  It is as though there is nothing in the array.  Wierd, eh?

Any suggestions?

Stuart.
0
 
LVL 5

Expert Comment

by:inter
ID: 1345117
Hi, sorry but the code works without modification. Just add a list box and a button to an empty form, copy and paste the code after implenetation clause and run. I am using Delphi 2.0. If you want I can send you the whole project and/or exe so that we can see if there is something with your windows.
About WN: (Examine my explanation below)

if GetWindowText(hwnd, wn,sizeof(wn)) <> 0 then //If windows has caption proceed
begin
    w:= Format('%6d ',[pid])+StrPas(wn); //StrPas routine converts the null terminated.
    S.Add...//add it to the list
end;
Friend, if this simple code does not works this should be do to some other thing which I can not understand by now.
Regards, Igor
0
 
LVL 6

Author Comment

by:Stuart_Johnson
ID: 1345118
Igor,

I humbly appologise for that.  I just took the word of someone else (granted I over looked it too).  Seems we made the mistake.


Thank you for your help!


Stuart.
0
 
LVL 5

Expert Comment

by:inter
ID: 1345119
You are wellcome, thanks!
0

Featured Post

Technology Partners: 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

Suggested Solutions

Title # Comments Views Activity
Delphi Form ownership 4 160
Strange behavior when a form is closed 6 79
Firemonkey webbrowser scrollbars ? 1 72
Tvertscrollbox like a whatsapp layout delete messages 1 50
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

751 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