Esopo
asked on
Listing the running applications with memory & processor usage
Please check the original Q at:
https://www.experts-exchange.com/questions/20940915/Listing-the-running-applications-with-memory-processor-usage.html
points for this particular Q will not be awarded, I'll ask for it's deletion in a couple of days.
Thank you.
https://www.experts-exchange.com/questions/20940915/Listing-the-running-applications-with-memory-processor-usage.html
points for this particular Q will not be awarded, I'll ask for it's deletion in a couple of days.
Thank you.
Sorry,
//select process in Listbox and click button
procedure TForm1.Button1Click(Sender : TObject);
var
PH : THandle;
hProcess : THandle;
lpCreationTime,
lpExitTime,
lpKernelTime,
lpUserTime : TFileTime;
begin
hProcess:= GetProcessId(ListBox1.Item s[ListBox1 .ItemIndex ]);
PH := OpenProcess(PROCESS_QUERY_ INFORMATIO N, FALSE, hProcess);
if PH <> 0 then
GetProcessTimes(PH, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
//example of showing TFileTime variable
ShowMessage(DateTimeToStr( FileTimeTo DateTime(l pCreationT ime)));
end;
Shane
//select process in Listbox and click button
procedure TForm1.Button1Click(Sender
var
PH : THandle;
hProcess : THandle;
lpCreationTime,
lpExitTime,
lpKernelTime,
lpUserTime : TFileTime;
begin
hProcess:= GetProcessId(ListBox1.Item
PH := OpenProcess(PROCESS_QUERY_
if PH <> 0 then
GetProcessTimes(PH, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
//example of showing TFileTime variable
ShowMessage(DateTimeToStr(
end;
Shane
ASKER
Shane, this will list all running process and the button tells the creation time, is that right?
Yes, bu there are other variables as well:
lpExitTime, lpKernelTime, lpUserTime
Shane
lpExitTime, lpKernelTime, lpUserTime
Shane
ASKER
Yes, i was looking into that. I did a simple changing with the lpCreationTime in the ShowMessage in your code, but the resulting numbers I don't get.
What are lpExitTime, lpKernelTime, lpUserTime, and how can I use them?
What are lpExitTime, lpKernelTime, lpUserTime, and how can I use them?
ASKER
I was actually reading that article, but although it explains how to use the values, it doesn't explain what Kernel mode and User mode are. Do you know?
I'll keep researching.
I'll keep researching.
No I don't sorry!
However, if you search google groups foe (Delphi + lpCreationTime) or any of the other values, you will see some of the information that is gathered using these values - Example , Computing CPU useage time, etc.
Shane
However, if you search google groups foe (Delphi + lpCreationTime) or any of the other values, you will see some of the information that is gathered using these values - Example , Computing CPU useage time, etc.
Shane
Did you look at the properties of TProcessEntry32;
var
ProcessEntry : TProcessEntry32;
Shane
var
ProcessEntry : TProcessEntry32;
Shane
I just found this
http://www.volweb.cz/pvones/delphi/
http://www.volweb.cz/pvones/delphi/ToolHlpViewer.htm
It says the code can be downloaded from the JEDI page
http://delphi-jedi.org/Jedi:JCLDOWNLOADS
Im gonna download it and look!
Shane
http://www.volweb.cz/pvones/delphi/
http://www.volweb.cz/pvones/delphi/ToolHlpViewer.htm
It says the code can be downloaded from the JEDI page
http://delphi-jedi.org/Jedi:JCLDOWNLOADS
Im gonna download it and look!
Shane
Yup, all those applications (ToolHelp Viewer), and their source code is available in the download (JCL)
Shane
Shane
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey guys!
I'm back. I know I deserve a name-calling session for leaving this Q out in the open for so long, but I had some issues that parted me from the net for a while.
Anyway, I'm back, got my hands on this project again and plan to see it through very soon. I'll be burning my brain with the code, hopefully we can come up with a function that will serve the delphi community for many years to come... (I feel I owe, you know?)
I'll be back with my findings very soon.
Esopo.
I'm back. I know I deserve a name-calling session for leaving this Q out in the open for so long, but I had some issues that parted me from the net for a while.
Anyway, I'm back, got my hands on this project again and plan to see it through very soon. I'll be burning my brain with the code, hopefully we can come up with a function that will serve the delphi community for many years to come... (I feel I owe, you know?)
I'll be back with my findings very soon.
Esopo.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TLHelp32, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure FormActivate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function GetWindowHandle(ProcessID:
function GetProcessID(ExeFile: String): DWORD;
function FileTimeToDateTime(FileTim
var
Form1: TForm1;
implementation
{$R *.dfm}
function FileTimeToDateTime(FileTim
var
SysTime : TSystemTime;
begin
FileTimeToSystemTime(FileT
with SysTime do
Result := EncodeDate(wYear, wMonth, wDay)
+ EncodeTime(wHour, wMinute, WSecond, wMilliseconds);
end;
function GetProcessID(ExeFile: String): DWORD;
var
Snapshot: THandle;
ProcessEntry: TProcessEntry32;
begin
Snapshot := CreateToolhelp32Snapshot(T
if Snapshot <> 0 then
try
ProcessEntry.dwSize := SizeOf(ProcessEntry);
if Process32First(Snapshot, ProcessEntry) then
repeat
if AnsiCompareText(ExeFile, ProcessEntry.szExeFile) = 0 then
begin
Result := ProcessEntry.th32ProcessID
Exit;
end;
until not Process32Next(Snapshot, ProcessEntry);
finally
CloseHandle(Snapshot);
end;
Result := 0;
end;
function GetWindowHandle(ProcessID:
var
Handle: HWND;
function EnumWindowProc(hwnd: HWND; lParam: LPARAM): BOOL;
var
ProcessID: DWORD;
begin
GetWindowThreadProcessId(h
Result := (ProcessID <> DWORD(lParam));
if not Result then
Handle := HWND;
end;
begin
if EnumWindows(@EnumWindowPro
Result := Handle
else
Result := 0;
end;
procedure TForm1.FormActivate(Sender
var
hSnapshot : THandle;
ProcessEntry : TProcessEntry32;
done : BOOL;
begin
try
hSnapshot := CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
ProcessEntry.dwSize := sizeof( TProcessEntry32 );
done := Process32First( hSnapshot, ProcessEntry );
while ( done = true ) do begin
ListBox1.Items.Add((Proces
done := Process32Next( hSnapshot, ProcessEntry );
end;
finally
CloseHandle( hSnapshot );
end;
end;
procedure TForm1.Button1Click(Sender
var
PH : THandle;
hProcess : THandle;
lpCreationTime,
lpExitTime,
lpKernelTime,
lpUserTime : TFileTime;
begin
hProcess:= GetProcessId(ListBox1.Item
PH := OpenProcess(PROCESS_QUERY_
if PH <> 0 then
GetProcessTimes(PH, lpCreationTime, lpExitTime, lpKernelTime, lpUserTime);
ShowMessage(DateTimeToStr(
end;
end.