Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Active Task List

Posted on 1998-05-12
5
Medium Priority
?
159 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 320 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

688 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