Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Running Applications ?

Posted on 2002-05-05
7
Medium Priority
?
166 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
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
Loops Section Overview
Screencast - Getting to Know the Pipeline

773 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