Solved

Active Task List

Posted on 1998-05-12
5
158 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

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.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
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…
Suggested Courses
Course of the Month5 days, 8 hours left to enroll

626 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