Solved

Active Task List

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

19 Experts available now in Live!

Get 1:1 Help Now