Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Running Applications ?

Posted on 2002-05-05
7
Medium Priority
?
164 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 800 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

718 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