Solved

Running Applications ?

Posted on 2002-05-05
7
156 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:mnasman
Comment Utility
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
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 7

Expert Comment

by:God_Ares
Comment Utility
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
Comment Utility
I'm so sorry

GetProcessTimes
Windows 95/98/Me: Unsupported.
0
 

Author Comment

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

Author Comment

by:Claud
Comment Utility
Thanx, for the running code...

tia

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

13 Experts available now in Live!

Get 1:1 Help Now