如何能够实现任务管理器中:应用程序、进程、性能 三个页面的功能?
应该是要用到window 的api,但是我没有用过window的api,不知道如何编程实现!
请大家帮帮忙!
最好给些实例!
应该是要用到window 的api,但是我没有用过window的api,不知道如何编程实现!
请大家帮帮忙!
最好给些实例!
解决方案 »
- 各位大哥,小弟想学DELPHI但不知道有那些书适合我,我是菜鸟.
- 我发现ORACLE的一个重大BUG:空值=任意值!
- 请教:这个问题如何下手?
- 请问在Delphi5下的Combobox怎么实现Delphi6的AutoDropDown功能?
- 用adodataset连接数据库,如何删除选中的记录?
- 可能是个很简单的问题,可我确实不会,请多多指教,很急!!!
- 很急:怎样访问念贴板的数据?(在线等)
- 新学delphi的,想找些模拟post提交的例子或教程,能推荐下吗?
- 那有图标下啊?~ ~
- 为什么使用ADO操作远程Sql Server7需要配置Client Network Utility?
- 这段代码为何不能打开我想打开的WORD文档呢?
- 如何得到系统所有进程的PID,所占CPU的百分比,内存使用!!!
里面说的很详细,剩下就是API的用法,你可以去查MSDN或者Windows SDK
我还有一条途径.可以得到几乎所有系统信息,那就是用WMI(Microsoft®Windows®Management Instrumentation)
参见:
http://www.microsoft.com/china/MSDN/library/enterprisedevelopment/softwaredev/WDdnclinicscripting.mspx
以下是用DELPHI写的得到系统所有进程信息的WMI(显示部分最好自己写一个)unit wmiu;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses
ActiveX, WbemScripting_TLB;
function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external 'activeds.dll';procedure DumpWMI_Process(Process: SWBemObject);
var
Enum: IEnumVARIANT;
varArr: OleVariant;
lNumElements: ULong;
SProp: ISWbemProperty;
Prop: OleVariant;
PropName: string;
PropType: string;
PropValue: string;
begin
Form1.Memo1.Lines.Add('+ WMI Path: ' + Process.Path_.Path);
Enum := Process.Properties_._NewEnum as IEnumVariant;
while (Succeeded(ADsEnumerateNext(Enum, 1, VarArr, lNumElements))) and
(lNumElements > 0) do
begin
if Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty, SProp)) and
Assigned(SProp) then
begin
try
PropName := SProp.Name;
Prop := SProp.Get_Value;
PropType := inttostr((VarType(Prop)));
PropValue := VarToStr(Prop);
Form1.Memo1.Lines.Add(' + ' + PropName + '[' + PropType + '] = ' + PropValue);
except
on E: Exception do
begin
// WriteLn(ErrOutput, PropName, ': ', E.Message);
end;
end;
end;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
Server: string;
Enum: IEnumVARIANT;
varArr: OleVariant;
lNumElements: ULong;
AName: array[0..255] of Char;
ASize: DWORD;
begin
if (ParamCount = 0) then
begin
Server := '';
ASize := SizeOf(AName) - 1;
if GetComputerName(@AName, ASize) then Server := AName;
end
else
begin
Server := ParamStr(1);
end;
try
Memo1.Lines.BeginUpdate;
Enum := CoSWbemLocator.Create.ConnectServer(Server, 'root\cimv2', '',
'', '', '', 0, nil).ExecQuery('Select * from Win32_Process', 'WQL',
wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;
while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and
(lNumElements > 0) do
begin
DumpWMI_Process(IUnknown(varArr) as SWBemObject);
end;
finally
Memo1.Lines.EndUpdate;
end;
end;end.
////其中,WbemScripting_TLB.pas可从
///http://www.truth4all.org/WbemScripting_TLB.pas
///下载你要得到系统的其它信息,只要将
'Select * from Win32_Process'
改成你要的关于WMI得到其它系统信息可见:
http://dev.csdn.net/Develop/article/23%5C23371.shtm
我现在用EnumWindows/CreateToolhelp32Snapshot的到了进程列表
可是得不到进程的cpu时间和内存使用情况,如何实现任务管理器中性能页面的cpu使用记录和内存使用记录的功能呢?
MemoryStatus: TMemoryStatus;
begin
FillChar(MemoryStatus, SizeOf(TMemoryStatus), 0);
GlobalMemoryStatus(MemoryStatus);
for i:=0 to RzTreeView1.Items.Count-1 do
begin
Label1.Caption:=IntToStr(MemoryStatus.dwTotalPhys div 1024)+' KB');//物理内存总数
Label2.Caption:=IntToStr(MemoryStatus.dwAvailPhys div 1024)+' KB';//物理内存剩余
Label3.Caption:=IntToStr(MemoryStatus.dwTotalVirtual div 1024)+' KB');//虚拟内存总数
Label4.Caption:=IntToStr(MemoryStatus.dwAvailVirtual div 1024)+' KB';//虚拟内存剩余
end;
end;
MemoryStatus: TMemoryStatus;
begin
FillChar(MemoryStatus, SizeOf(TMemoryStatus), 0);
GlobalMemoryStatus(MemoryStatus);
Label1.Caption:=IntToStr(MemoryStatus.dwTotalPhys div 1024)+' KB');//物理内存总数
Label2.Caption:=IntToStr(MemoryStatus.dwAvailPhys div 1024)+' KB';//物理内存剩余
Label3.Caption:=IntToStr(MemoryStatus.dwTotalVirtual div 1024)+' KB');//虚拟内存总数
Label4.Caption:=IntToStr(MemoryStatus.dwAvailVirtual div 1024)+' KB';//虚拟内存剩余
end;
用性能计数器可以得到进程的CPU使用率
具体用法参见:http://www.vckbase.com/document/viewdoc/?id=1434
==================
implementationuses pdh;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var
hq : HQUERY;
pdhStatus : PDH_STATUS;
CounterHandle : HCOUNTER;
fmtValue : TPdhFmtCounterValue ;
dwctrType : DWORD;
procedure PdhCheck(const Error : Integer);
begin
if Error<> ERROR_SUCCESS then
raise Exception.Create('Error'+IntToHex(8,Error));
end;
begin
hq := 0;
pdhStatus := PdhOpenQuery(nil,0,hq);
PdhCheck(pdhStatus);
try
pdhStatus := PdhAddCounter ( hq ,
pchar('\Process(QQ)\% Processor Time'),
0,
CounterHandle ) ;
PdhCheck(pdhStatus);
pdhStatus := PdhCollectQueryData ( hq ) ;
PdhCheck(pdhStatus);
pdhStatus := PdhGetFormattedCounterValue ( CounterHandle,
PDH_FMT_DOUBLE,
@dwctrType,
fmtValue ) ;
PdhCheck(pdhStatus);
Showmessage(FormatFloat('0.0000000000000',fmtValue.doubleValue));
finally
pdhStatus := PdhCloseQuery (hq) ;
PdhCheck(pdhStatus);
end;
end;
============================================unit pdh;interface
uses windows;
type
HCOUNTER = THandle;
HQUERY = THandle;
PDH_STATUS = Longint;
DWORD_PTR = DWORD;
_PDH_FMT_COUNTERVALUE = record
CStatus: DWORD;
case Longint of
1: (longValue: Longint);
2: (doubleValue: Double);
3: (largeValue: LONGLONG);
4: (AnsiStringValue: LPSTR);
5: (WideStringValue: LPWSTR);
end;
TPdhFmtCounterValue = _PDH_FMT_COUNTERVALUE;function PdhOpenQuery(szDataSource: PChar; dwUserData: DWORD_PTR;
var phQuery: HQUERY): Longint; stdcall;function PdhAddCounter(hQuery: HQUERY; szFullCounterPath: PChar;
dwUserData: DWORD_PTR; var phCounter: HCOUNTER): Longint; stdcall;function PdhCollectQueryData(hQuery: HQUERY): Longint; stdcall;function PdhGetFormattedCounterValue(hCounter: HCOUNTER; dwFormat: DWORD;
lpdwType: LPDWORD; var pValue: TPdhFmtCounterValue): Longint; stdcall;function PdhCloseQuery(hQuery: HQUERY): Longint; stdcall;const
PDH_FMT_DOUBLE = DWORD($00000200);implementationfunction PdhOpenQuery; external 'pdh.dll' name 'PdhOpenQuery';
function PdhAddCounter; external 'pdh.dll' name 'PdhAddCounterA';
function PdhCollectQueryData; external 'pdh.dll' name 'PdhCollectQueryData';
function PdhGetFormattedCounterValue; external 'pdh.dll' name 'PdhGetFormattedCounterValue';
function PdhCloseQuery; external 'pdh.dll' name 'PdhCloseQuery';end.
pchar('\Process(QQ)\% Processor Time'),
0,
CounterHandle ) ;
只添加了QQ.exe的计数器, 如何用循环添加所有的进程的计数器?
http://www.delphibbs.com/keylife/iblog_show.asp?xid=12322
邮箱:
[email protected]
unit WinMain;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, Menus, ImgList, ActnList;
Const
MAX_INTERFACE_NAME_LEN = 256;
MAXLEN_PHYSADDR = 8;
MAXLEN_IFDESCR = 256;
ANY_SIZE = 1;type
PVOID = Pointer;
NTSTATUS = LongInt; PUNICODE_STRING = ^TNtUnicodeString;
_UNICODE_STRING = packed record
Length: Word;
MaximumLength: Word;
Buffer: PWideChar;
end;
UNICODE_STRING = _UNICODE_STRING;
TNtUnicodeString = _UNICODE_STRING; PCLIENT_ID = ^TClientId;
_CLIENT_ID = packed record
UniqueProcess: THandle;
UniqueThread: THandle;
end;
TClientId = _CLIENT_ID;
CLIENT_ID = _CLIENT_ID;
//对应 SystemBasicInformation 0号调用
PSYSTEM_BASIC_INFORMATION = ^TSystemBasicInformation;
_SYSTEM_BASIC_INFORMATION = packed record
dwUnknown1: DWORD;
uKeMaximumIncrement: ULONG;
uPageSize: ULONG; //一个内存页的大小 //2c
uMmNumberOfPhysicalPages: ULONG; //系统管理着多少个页 //28
uMmLowestPhysicalPage: ULONG;
uMmHighestPhysicalPage: ULONG;
uAllocationGranularity: ULONG;
pLowestUserAddress: Pointer;
pMmHighestUserAddress: Pointer;
uKeActiveProcessors: ULONG;
bKeNumberProcessors: BYTE;
bUnknown2: BYTE;
wUnknown3: WORD;
end;
TSystemBasicInformation = _SYSTEM_BASIC_INFORMATION;
SYSTEM_BASIC_INFORMATION = _SYSTEM_BASIC_INFORMATION;
//对应 SystemPerformanceInformation 2号调用
PSYSTEM_PERFORMANCE_INFORMATION = ^TSystemPerformanceInformation;
_SYSTEM_PERFORMANCE_INFORMATION = packed record
liIdleTime: LARGE_INTEGER;
IoReadTransferCount: LARGE_INTEGER;
IoWriteTransferCount: LARGE_INTEGER;
IoOtherTransferCount: LARGE_INTEGER;
IoReadOperationCount: ULONG;
IoWriteOperationCount: ULONG;
IoOtherOperationCount: ULONG;
AvailablePages: ULONG;
CommittedPages: ULONG;
CommitLimit: ULONG;
PeakCommitment: ULONG;
PageFaultCount: ULONG;
CopyOnWriteCount: ULONG;
TransitionCount: ULONG;
CacheTransitionCount: ULONG;
DemandZeroCount: ULONG;
PageReadCount: ULONG;
PageReadIoCount: ULONG;
CacheReadCount: ULONG;
CacheIoCount: ULONG;
DirtyPagesWriteCount: ULONG;
DirtyWriteIoCount: ULONG;
MappedPagesWriteCount: ULONG;
MappedWriteIoCount: ULONG;
PagedPoolPages: ULONG;
NonPagedPoolPages: ULONG;
PagedPoolAllocs: ULONG;
PagedPoolFrees: ULONG;
NonPagedPoolAllocs: ULONG;
NonPagedPoolFrees: ULONG;
FreeSystemPtes: ULONG;
ResidentSystemCodePage: ULONG;
TotalSystemDriverPages: ULONG;
TotalSystemCodePages: ULONG;
NonPagedPoolLookasideHits: ULONG;
PagedPoolLookasideHits: ULONG;
Spare3Count: ULONG;
ResidentSystemCachePage: ULONG;
ResidentPagedPoolPage: ULONG;
ResidentSystemDriverPage: ULONG;
CcFastReadNoWait: ULONG;
CcFastReadWait: ULONG;
CcFastReadResourceMiss: ULONG;
CcFastReadNotPossible: ULONG;
CcFastMdlReadNoWait: ULONG;
CcFastMdlReadWait: ULONG;
CcFastMdlReadResourceMiss: ULONG;
CcFastMdlReadNotPossible: ULONG;
CcMapDataNoWait: ULONG;
CcMapDataWait: ULONG;
CcMapDataNoWaitMiss: ULONG;
CcMapDataWaitMiss: ULONG;
CcPinMappedDataCount: ULONG;
CcPinReadNoWait: ULONG;
CcPinReadWait: ULONG;
CcPinReadNoWaitMiss: ULONG;
CcPinReadWaitMiss: ULONG;
CcCopyReadNoWait: ULONG;
CcCopyReadWait: ULONG;
CcCopyReadNoWaitMiss: ULONG;
CcCopyReadWaitMiss: ULONG;
CcMdlReadNoWait: ULONG;
CcMdlReadWait: ULONG;
CcMdlReadNoWaitMiss: ULONG;
CcMdlReadWaitMiss: ULONG;
CcReadAheadIos: ULONG;
CcLazyWriteIos: ULONG;
CcLazyWritePages: ULONG;
CcDataFlushes: ULONG;
CcDataPages: ULONG;
ContextSwitches: ULONG;
FirstLevelTbFills: ULONG;
SecondLevelTbFills: ULONG;
SystemCalls: ULONG;
end;
TSystemPerformanceInformation = _SYSTEM_PERFORMANCE_INFORMATION;
SYSTEM_PERFORMANCE_INFORMATION = _SYSTEM_PERFORMANCE_INFORMATION;
PVM_COUNTERS = ^TVmCounters;
_VM_COUNTERS = packed record
uPeakVirtualSize: ULONG;
uVirtualSize: ULONG;
uPageFaultCount: ULONG;
uPeakWorkingSetSize: ULONG;
uWorkingSetSize: ULONG;
uQuotaPeakPagedPoolUsage: ULONG;
uQuotaPagedPoolUsage: ULONG;
uQuotaPeakNonPagedPoolUsage: ULONG;
uQuotaNonPagedPoolUsage: ULONG;
uPagefileUsage: ULONG;
uPeakPagefileUsage: ULONG;
end;
TVmCounters = _VM_COUNTERS;
VM_COUNTERS = _VM_COUNTERS;
PIO_COUNTERSEX = ^TIoCountersex;
_IO_COUNTERSEX = packed record
ReadOperationCount: LARGE_INTEGER;
WriteOperationCount: LARGE_INTEGER;
OtherOperationCount: LARGE_INTEGER;
ReadTransferCount: LARGE_INTEGER;
WriteTransferCount: LARGE_INTEGER;
OtherTransferCount: LARGE_INTEGER;
end;
TIoCountersex = _IO_COUNTERSEX;
IO_COUNTERSEX = _IO_COUNTERSEX; PSYSTEM_THREAD_INFORMATION = ^TSystemThreadInfo;
_SYSTEM_THREAD_INFORMATION = packed record
KernelTime: LARGE_INTEGER;
UserTime: LARGE_INTEGER;
CreateTime: LARGE_INTEGER;
WaitTime: DWORD;
pStartAddress: PVOID;
Cid: CLIENT_ID;
Priority: DWORD;
BasePriority: DWORD;
ContextSwitches: DWORD;
ThreadState: DWORD;
WaitReason: DWORD;
uReserved01: DWORD;
end; //$040
TSystemThreadInfo = _SYSTEM_THREAD_INFORMATION;
SYSTEM_THREAD_INFORMATION = _SYSTEM_THREAD_INFORMATION; PSYSTEM_PROCESS = ^TSystemProcess;
_SYSTEM_PROCESS = packed record
uNext: DWORD;
ThreadCount: DWORD;
Reserved01: LARGE_INTEGER;
Reserved02: LARGE_INTEGER;
Reserved03: LARGE_INTEGER;
CreateTime: LARGE_INTEGER;
UserTime: LARGE_INTEGER;
KernelTime: LARGE_INTEGER;
usName: UNICODE_STRING;
BasePriority: DWORD;
UniqueProcessId: DWORD;
InheritedFromUniqueProcessId: DWORD;
HandleCount: DWORD;
SessionId: DWORD;
Reserved08: DWORD;
VmCounters: VM_COUNTERS;
CommitCharge: DWORD;
end;
TSystemProcess = _SYSTEM_PROCESS;
SYSTEM_PROCESS = _SYSTEM_PROCESS; PSYSTEM_PROCESS_NT4 = ^TSystemProcessNt4;
_SYSTEM_PROCESS_NT4 = packed record
Process: SYSTEM_PROCESS;
Threads: SYSTEM_THREAD_INFORMATION;
end;
TSystemProcessNt4 = _SYSTEM_PROCESS_NT4;
SYSTEM_PROCESS_NT4 = _SYSTEM_PROCESS_NT4; PSYSTEM_PROCESS_NT5 = ^TSystemProcessNt5;
_SYSTEM_PROCESS_NT5 = packed record // Windows 2000
Process: SYSTEM_PROCESS; // common members //$000
IoCounters: IO_COUNTERSEX; // see ntddk.h //$088
aThreads: SYSTEM_THREAD_INFORMATION; // thread array //$0B8
end; //$0B8
TSystemProcessNt5 = _SYSTEM_PROCESS_NT5;
SYSTEM_PROCESS_NT5 = _SYSTEM_PROCESS_NT5; //对应 SystemProcessInformation 5号调用
PSYSTEM_PROCESS_INFORMATION = ^TSystemProcessInformation;
_SYSTEM_PROCESS_INFORMATION = packed record
case Integer of
0: (Process_NT4: SYSTEM_PROCESS_NT4);
1: (Process_NT5: SYSTEM_PROCESS_NT5);
end;
TSystemProcessInformation = _SYSTEM_PROCESS_INFORMATION;
SYSTEM_PROCESS_INFORMATION = _SYSTEM_PROCESS_INFORMATION;
//对应 SystemProcessorPerformanceInformation 8号调用
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = ^TSystemProcessorPerformanceInformation;
_SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = packed record
IdleTime: LARGE_INTEGER;
KernelTime: LARGE_INTEGER;
UserTime: LARGE_INTEGER;
DpcTime: LARGE_INTEGER;
InterruptTime: LARGE_INTEGER;
InterruptCount: DWORD;
dwUnknown1: DWORD;
end;
TSystemProcessorPerformanceInformation = _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION = _SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION;
// 对应 SystemFileCacheInformation 21号调用
PSYSTEM_CACHE_INFORMATION = ^TSystemFileCacheInformation;
_SYSTEM_CACHE_INFORMATION = packed record
uFileCache: ULONG; // bytes
uFileCachePeak: ULONG; // bytes
PageFaultCount: ULONG;
MinimumWorkingSet: ULONG;
MaximumWorkingSet: ULONG;
TransitionSharedPages: ULONG;
TransitionSharedPagesPeak: ULONG;
Reserved: array[0..1] of ULONG;
end;
TSystemFileCacheInformation = _SYSTEM_CACHE_INFORMATION;
SYSTEM_CACHE_INFORMATION = _SYSTEM_CACHE_INFORMATION;
PTMIB_IfRow = ^TMIB_IfRow;
TMIB_IfRow = packed record
wszName: array[1..MAX_INTERFACE_NAME_LEN] of WChar;
dwIndex: DWORD;
dwType: DWORD;
dwMTU: DWORD;
dwSpeed: DWORD;
dwPhysAddrLen: DWORD;
bPhysAddr: array[1..MAXLEN_PHYSADDR] of byte;
dwAdminStatus: DWORD;
dwOperStatus: DWORD;
dwLastChange: DWORD;
dwInOctets: DWORD;
dwInUcastPkts: DWORD;
dwInNUCastPkts: DWORD;
dwInDiscards: DWORD;
dwInErrors: DWORD;
dwInUnknownProtos: DWORD;
dwOutOctets: DWORD;
dwOutUCastPkts: DWORD;
dwOutNUCastPkts: DWORD;
dwOutDiscards: DWORD;
dwOutErrors: DWORD;
dwOutQLen: DWORD;
dwDescrLen: DWORD;
bDescr: array[1..MAXLEN_IFDESCR] of char; //byte;
end;
TMIB_IfArray = array of TMIB_IFRow;
PTMIB_IfTable = ^TMIB_IfTable;
TMIB_IfTable = packed record
dwNumEntries: DWORD;
Table: array[0..ANY_SIZE - 1] of TMIB_IfRow;
end;
Const
STATUS_INFO_LENGTH_MISMATCH = NTSTATUS($C0000004);
TMainForm = class(TForm)
WinMain_StatusBar: TStatusBar;
WinMain_PageControl: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
TabSheet4: TTabSheet;
TabSheet5: TTabSheet;
Stop_Button: TButton;
Change_Button: TButton;
CPUStatus_GroupBox: TGroupBox;
CPU_Shape: TShape;
Process_ListView: TListView;
WinMain_Menu: TMainMenu;
F1: TMenuItem;
O1: TMenuItem;
V1: TMenuItem;
H1: TMenuItem;
PFStatus_GroupBox: TGroupBox;
PFStatus_Shape: TShape;
CPUStatusLog_GroupBox: TGroupBox;
CPUStatusLog_Shape: TShape;
PFStatusLog_GroupBox: TGroupBox;
PFStatusLog_Shape: TShape;
GroupBox1: TGroupBox;
Task_ListView: TListView;
Close_Button: TButton;
GroupBox2: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
GroupBox3: TGroupBox;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
GroupBox4: TGroupBox;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
GroupBox5: TGroupBox;
Label19: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
Timer1: TTimer;
Lan_GroupBox: TGroupBox;
Lan_ListView: TListView;
Lan_Shape: TShape;
Shape1: TShape; procedure GetCOMStatus;
procedure GetLanStatus;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private public end;//引入函数
function NtQuerySystemInformation(
SystemPerformanceInformation: ULONG;
pSystemInformationClass: PVOID;
uSystemInformationClass: ULONG;
puReturnLength: PULONG
): NTSTATUS; stdcall;external 'ntdll.dll';function GetIfTable(
pIfTable: PTMib_IfTable;
pdwSize: PULONG;
bOrder: boolean
): DWORD; stdCall; external 'IPHLPAPI.DLL';var
MainForm: TMainForm;implementation
{$R *.dfm}procedure TMainForm.GetCOMStatus;var
Status: NTSTATUS;
SysPerfInfo: TSystemPerformanceInformation;
SysBasicInfo:TSystemBasicInformation;
SysCacheInfo:TSystemFileCacheInformation;
PageSize:Single;
begin
status := NtQuerySystemInformation(0, @SysBasicInfo, SizeOf(TSystemBasicInformation), nil);
if status <> 0 then
Exit;
PageSize := SysBasicInfo.uPageSize / 1024;
status := NtQuerySystemInformation(2, @SysPerfInfo, SizeOf(TSystemPerformanceInformation), nil);
if status <> 0 then
Exit;
//内存使用率 = (页面大小 / 1024) * CommittedPages
//MEMUsage := (PageSize shr 10) * SysPerfInfo.CommittedPages;
Label24.Caption := FloatToStr(SysPerfInfo.PagedPoolPages * PageSize + SysPerfInfo.NonPagedPoolPages * PageSize);
Label23.Caption := FloatToStr(SysPerfInfo.PagedPoolPages * PageSize);
Label22.Caption := FloatToStr(SysPerfInfo.NonPagedPoolPages * PageSize);
Label18.Caption := FloatToStr(SysPerfInfo.CommittedPages * PageSize);
Label17.Caption := FloatToStr(SysPerfInfo.CommitLimit * PageSize);
Label16.Caption := FloatToStr(SysPerfInfo.PeakCommitment * PageSize); Label12.Caption := FloatToStr(SysBasicInfo.uMmNumberOfPhysicalPages * PageSize);
Label11.Caption := FloatToStr(SysPerfInfo.AvailablePages * PageSize);
//Label10.Caption := FloatToStr(SysPerfInfo.ResidentSystemCachePage * PageSize);
status := NtQuerySystemInformation(21, @SysCacheInfo, SizeOf(TSystemFileCacheInformation), nil);
if status <> 0 then
Exit;
Label10.Caption := FloatToStr(SysCacheInfo.uFileCache / 1024);
WinMain_StatusBar.Panels.Items[2].Text := '内存使用: ' + Label18.Caption + 'K / ' + Label17.Caption + 'K';
end;
procedure TMainForm.GetLanStatus;
var
IfRow : TMib_IfRow;
i,Error,TableSize : integer;
pBuf : PChar;
NumEntries : DWORD;
sDescr : string;
Lan_List : Tlistitem;
begin
TableSize := 0;
Error := GetIfTable( PTMib_IfTable( pBuf ), @TableSize, false );
if Error <> ERROR_INSUFFICIENT_BUFFER then
EXIT;
GetMem( pBuf, TableSize );
Error := GetIfTable( PTMib_IfTable( pBuf ), @TableSize, false );
if Error = NO_ERROR then
begin
NumEntries := PTMib_IfTable( pBuf )^.dwNumEntries;
if NumEntries > 0 then
begin
inc( pBuf, SizeOf( NumEntries ) );
for i := 1 to NumEntries do
begin
IfRow := PTMib_IfRow( pBuf )^;
with IfRow do
begin
SetLength( sDescr, dwDescrLen );
move( bDescr, sDescr[1], Length( sDescr ) );
sDescr := trim( sDescr );
Lan_List :=Lan_ListView.Items.Add;
Lan_List.Caption := '';
Lan_List.SubItems.Add(sDescr);
Lan_List.SubItems.Add(Format('%.0f',[(dwInOctets + dwOutOctets) / dwSpeed]) + ' %');
Lan_List.SubItems.Add(Format('%s',[FloatToStr(dwSpeed/1000000) + ' Mbps']));
end;
inc( pBuf, SizeOf( IfRow ) );
end;
end
else begin
////////////
end;
end
else begin
/////ItemList.Add( SysErrorMessage( GetLastError ) );
end;
dec( pBuf, SizeOf( DWORD ) + NumEntries * SizeOf( IfRow ) );
FreeMem( pBuf );
end;
procedure TMainForm.FormCreate(Sender: TObject);
begin
GetCOMStatus;
GetLanStatus;
end;procedure TMainForm.Timer1Timer(Sender: TObject);
begin
GetCOMStatus;
end;end.
进程遍历容易实现,但是进程的 cpu时间 和 内存使用 这两个指标如何得到?