Solved

Running Applications ?

Posted on 2002-05-05
7
162 Views
Last Modified: 2010-04-04
How can I get the running Application.
Like the Taskmonitor form WinNt do.
I working with Win98/ME

Thanx
0
Comment
Question by:Claud
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 6990264
Hello

  Here's code will return the all processes, I got it from Code central in borland site


unit GetProcess;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses
  TLHelp32, PsApi;

function RunningProcessesList(List: TStrings): Boolean;

  function BuildListTH: Boolean;
  var
    SnapProcHandle: THandle;
    ProcEntry: TProcessEntry32;
    NextProc: Boolean;
  begin
    SnapProcHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if SnapProcHandle <> THandle(-1) then
    begin
      Result := True;
      ProcEntry.dwSize := Sizeof(ProcEntry);
      NextProc := Process32First(SnapProcHandle, ProcEntry);
      while NextProc do
      begin
        List.AddObject(ProcEntry.szExeFile, Pointer(ProcEntry.th32ProcessID));
        NextProc := Process32Next(SnapProcHandle, ProcEntry);
      end;
      CloseHandle(SnapProcHandle);
    end else
      Result := False;
  end;

  function BuildListPS: Boolean;
  var
    PIDs: array[0..1024] of DWORD;
    Handle: THandle;
    Needed: DWORD;
    I: Integer;
    ModuleFileName: array[0..MAX_PATH] of Char;
  begin
    Result := EnumProcesses(@PIDs, Sizeof(PIDs), Needed);
    if not Result then Exit;
    for I := 0 to (Needed div Sizeof(DWORD)) - 1 do
      if PIDs[I] <> 0 then
      begin
        Handle := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, PIDs[I]);
        if Handle <> 0 then
        begin
          if GetModuleFileNameEx(Handle, 0, ModuleFileName, Sizeof(ModuleFileName)) = 0 then
            List.AddObject('[System]', Pointer(INVALID_HANDLE_VALUE))
          else
            List.AddObject(ModuleFileName, Pointer(PIDs[I]));
          CloseHandle(Handle);
        end;
      end;
  end;

begin
  Assert(Assigned(List));
  List.BeginUpdate;
  try
    List.Clear;
    if (Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion = 4) then
      Result := BuildListPS
    else
      Result := BuildListTH;
  finally
    List.EndUpdate;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  RunningProcessesList(ListBox1.Items);
end;

procedure TForm1.FormShow(Sender: TObject);
begin
  Button1Click(nil);
end;

end.
0
 
LVL 8

Expert Comment

by:Cesario
ID: 6990333
Dear Mnasman ;-)

your code will return the Tabsheet with Process in the Taskmonitor but the Application TabSheet.

Its possible to get this form the Taskbar.

Cesario
0
 
LVL 8

Accepted Solution

by:
Cesario earned 200 total points
ID: 6990507
Claud, if you are looking for the runing tasks so just use GetTasksList function (JclSysInfo unit) from JCL:
http://delphi-jedi.org/Jedi:CODELIBJCL


Try this Exmaple:
function GetTasksList(const List: TStrings): Boolean;

  function EnumWindowsProc(Wnd: HWND; List: TStrings): Boolean; stdcall;
  var
    ParentWnd: HWND;
    ExStyle: DWORD;
    Caption: array [0..255] of Char;
  begin
    if IsWindowVisible(Wnd) then
    begin
      ParentWnd := GetWindowLong(Wnd, GWL_HWNDPARENT);
      ExStyle := GetWindowLong(Wnd, GWL_EXSTYLE);
      if ((ParentWnd = 0) or (ParentWnd = GetDesktopWindow)) and
        ((ExStyle and WS_EX_TOOLWINDOW = 0) or (ExStyle and WS_EX_APPWINDOW <> 0)) and
        (GetWindowText(Wnd, Caption, SizeOf(Caption)) > 0) then
          List.AddObject(Caption, Pointer(Wnd));
    end;
    Result := True;
  end;

begin
  Result := EnumWindows(@EnumWindowsProc, Integer(List));
end;

good luck
0
Independent Software Vendors: 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!

 
LVL 7

Expert Comment

by:God_Ares
ID: 6991164
btw.. if you want to know how much cpu time all processes have been using, don't try to find some api call (i did that) it's a calculation..

check all processes and see how much time they used int a intervall

procedure TForm1.Button2Click(Sender: TObject);

Function x(t:_systemtime):String;
var s:string;
Begin
  s:= IntToStr(t.wYear);
  s:=s + '-' + IntToStr(t.wMonth);
  s:=s + '-' + IntToStr(t.wDay);
  s:=s + ' @ ' + IntToStr(t.wHour);
  s:=s + ':' + IntToStr(t.wMinute);
  s:=s + '.' + IntToStr(t.wSecond);
  result := s;
end;


var a,b,c,d : _filetime;
    t:_systemtime;
begin
//this is it!
 GetProcessTimes(GetCurrentProcess
                ,a
                ,b
                ,c
                ,d);


// specifies the process of interest
//    LPFILETIME lpCreationTime,     // when the process was created
//    LPFILETIME lpExitTime,     // when the process exited
//    LPFILETIME lpKernelTime,     // time the process has spent in kernel mode
//    LPFILETIME lpUserTime      // time the process has spent in user mode
//   );
  memo1.Clear;
  FileTimeToSystemTime(a,t); memo1.lines.add('Created ' + x(t));
  FileTimeToSystemTime(b,t); memo1.lines.add('Exited ' + x(t));
  FileTimeToSystemTime(c,t); memo1.lines.add('kernel ' + x(t));
  FileTimeToSystemTime(d,t); memo1.lines.add('user ' + x(t));

end;


just a comment.
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 6991166
I'm so sorry

GetProcessTimes
Windows 95/98/Me: Unsupported.
0
 

Author Comment

by:Claud
ID: 7033511
Thanx Expers. But Jedi Code was very usful. Cesario the Points are 4u.
0
 

Author Comment

by:Claud
ID: 7065708
Thanx, for the running code...

tia

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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