取得所有进程后,怎么取得该进程的使用内存总数!(100分)

  • 主题发起人 主题发起人 bamfk1023
  • 开始时间 开始时间
B

bamfk1023

Unregistered / Unconfirmed
GUEST, unregistred user!
Hand := CreateToolhelp32Snapshot(TH32CS_SNAPALL,0);<br> &nbsp;lppe.dwSize &nbsp; := &nbsp; SizeOf(lppe);<br> &nbsp;found := Process32First(Hand,lppe);<br> &nbsp;while found do<br> &nbsp;begin<br> &nbsp; &nbsp;item.subitems.BeginUpdate;<br> &nbsp; &nbsp;item:=listview1.Items.Add;<br> &nbsp; &nbsp;item.Caption:=lppe.szExeFile;<br> &nbsp; &nbsp;item.SubItems.add(inttostr(lppe.th32ProcessID));<br> &nbsp; &nbsp;item.SubItems.add(inttostr(GetProcessMemUsage(lppe.th32ProcessID))); &nbsp; ///到处都是这个函数,这个函数是哪里来的<br> &nbsp; &nbsp;item.SubItems.endupdate;<br> &nbsp;found := Process32Next(Hand,lppe);<br> &nbsp;end;
 
话题1360311的标题是:检测某个程序占用的内存(急) (200分)<br>分类:Windows API(Delphi)gztoms(2002-10-05 12:08) <br>各位大虾:<br> &nbsp; &nbsp;有谁知道用什么API函数能检测出某一程序占用的内存,<br>相当于在“任务管理器”里的“进程”叶中所看到的一样。<br> &nbsp; 多谢了!!!<br> <br>kcahcn(2002-10-10 07:49) <br>任务管理器调用 NtQuerySystemInformation 。还可以用NtQueryInformationProcess.<br>两者都是本机API(Native API) . <br>也可以用GetProcessMemoryInfo 包含在PsAPI.<br>GetPMem(PID:DWORD);<br>var<br> &nbsp; &nbsp;pmc: PPROCESS_MEMORY_COUNTERS;<br> &nbsp; &nbsp;cb: Integer;<br> &nbsp; &nbsp;phandle:Thandle;<br>begin<br>phandle:=OpenProcess(PROCESS_ALL_ACCESS,false,PID);<br>cb := sizeof(_PROCESS_MEMORY_COUNTERS);<br> GetMem(pmc, cb);<br> pmc^.cb := cb;<br> if GetProcessMemoryInfo(phandle, pmc, cb) then<br> &nbsp;ShowMessage(IntToStr(pmc^.WorkingSetSize))<br> else<br> &nbsp;ShowMessage('错误');<br>end;<br> <br>gztoms(2002-10-05 17:46) <br>请问kcahcn:<br> &nbsp;参数PID是要传递什么?<br> <br>duducat(2002-10-05 19:00) <br>pid 进程ID<br> <br>kcahcn(2002-10-06 01:11) <br>Thanks duducat .PID -&gt; 进程ID<br><br>下面是个用NtQueryInformationProcess的例子 : &nbsp;[ NT ,2K,XP ]<br>// 参考: Windows NT/2000 本机API (Gary Nebbett)<br>// Tested using Delphi 6.0, 7.0 On WinXP <br>type<br> &nbsp;PVM_Counters=^TVM_Counters;<br> &nbsp;TVM_Counters=record<br> &nbsp; &nbsp; &nbsp; &nbsp;PeakVirtualSize:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;VirtualSize:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;PagedFaultCount:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;PeakWorkingSetSize:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;WorkingSetSize:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;QuotaPeakPagedPoolUsage:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;QuotaPagedPoolUsage:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;QuotaPeakNonPagedPoolUsage:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;QuotaNonPagedPoolUsage:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;PagefileUsage:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp;PeakPagefileUsage:ULONG;<br> &nbsp;end;<br>const ProcessVMCounters =3;<br>...<br>function NtQueryInformationProcess<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProcessHandle: Thandle;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PrcInfoClass:DWORD ;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PrcInfo:Pointer ;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PrcInfoLength:ULONG;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;returnlength: TPDword<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;):<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DWORD; stdcall ;external 'ntdll.dll' name 'NtQueryInformationProcess';<br>// 可以用动态调用(隐式装入)<br>....<br>// Our Function here:<br>function GetPrcVMCounters(PID:DWORD):TStringList;<br>var<br>status:DWORD;<br>retlen:DWORD;<br>VM_Info:TVM_Counters;<br>hProcess:THandle;<br>begin<br>result:=TStringList.Create;<br>hProcess :=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,PID);<br>status:=NtQueryInformationProcess<br> &nbsp; &nbsp; &nbsp; &nbsp;(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hProcess,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ProcessVMCounters,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@VM_Info,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sizeof(TVM_Counters),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@retlen<br> &nbsp; &nbsp; &nbsp; &nbsp;);<br>if(status&lt;&gt;0) then<br>begin<br> &nbsp; ShowMessage('NtQueryInformationProcess 失败');<br> &nbsp; exit;<br>end;<br>with result do<br>begin<br>Add('进程虚拟地址空间的最大数值 : &nbsp;'+IntToStr(VM_Info.PeakVirtualSize)+' &nbsp;Byte');<br>Add('进程的虚拟地址空间的大小 : &nbsp;'+IntToStr(VM_Info.VirtualSize)+' &nbsp;Byte');<br>Add('进程分页错误数目 : &nbsp;'+IntToStr(VM_Info.PagedFaultCount)+' &nbsp;Byte');<br>Add('进程的工作集列表的最大值 : &nbsp;'+IntToStr(VM_Info.PeakWorkingSetSize)+' &nbsp;Byte');<br>Add('进程的工作集列表的大小 : &nbsp;'+IntToStr(VM_Info.WorkingSetSize)+' &nbsp;Byte'); &nbsp;// &lt;--- 就是这个 [:D]<br>Add('填充到进程的分页池的峰值的最大值 : &nbsp;'+IntToStr(VM_Info.QuotaPeakPagedPoolUsage)+' &nbsp;Byte');<br>Add('填充到进程的分页池的峰值大小 : &nbsp;'+IntToStr(VM_Info.QuotaPagedPoolUsage)+' &nbsp;Byte');<br>Add('填充到进程的非分页池的峰值的最大值 : &nbsp;'+IntToStr(VM_Info.QuotaNonPagedPoolUsage)+' &nbsp;Byte');<br>Add('填充到进程的分页池的峰值大小 : &nbsp;'+IntToStr(VM_Info.QuotaNonPagedPoolUsage)+' &nbsp;Byte');<br>Add('进程多使用的页文件页的最大值 : &nbsp;'+IntToStr(VM_Info.PeakPagefileUsage)+' &nbsp;Byte');<br>end;<br>end;<br>// ----<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br> &nbsp;Memo1.Lines:=GetPrcVMCounters(256);<br>end;<br><br>-------------------------<br>CIONO1<br> <br>duducat(2002-10-08 08:27) <br>to kcahcn <br>TPDword=PWORD;<br><br>为什么以上方法对PID=0的Idle Process进程占有的物理内存显示不正确??:))<br>2000下面应该为16K,XP下面是24K,以上方法中GetProcessMemoryInfo显示的是变化的,<br>数值根本不对,NtQueryInformationProcess则显示的为0!<br> <br>duducat(2002-10-08 08:32) <br>另外进程CPU占用率也是一个有点技术含量的问题,不知道各位大侠解决没有?<br> <br>duducat(2002-10-08 08:40) <br>最后9X下面物理内存的使用也是个头痛的问题,嘻嘻……<br>好像据我所知就TaskInfo2002解决的比较圆满(收费),<br>prcview(显示不正确)和processwalker则根本没有解决……(免费)<br>我想这是收费与免费的小小区别吧!<br>……<br>题外话,国产的进程管理器俺真是搞不懂,什么技术含量的问题都没有涉及<br>和解决,就要注册和收注册费了,真是丢中国人的脸……<br>严重了!!!!!!见谅!<br> <br>yyk518(2002-10-08 08:47) <br>做这些东西还有意义吗?技术含量再高,高得过M$吗?[:D]<br> <br>duducat(2002-10-08 09:17) <br>to yyk518 <br>那你永远做MS的最“忠实”用户好了:))好乖亚……<br>学计算机干吗??对你有意义嘛?<br>因为你和你的子孙学几百年都不会超过MS的技术高峰的<br><br> <br>yyk518(2002-10-09 08:54) <br>呵呵,这么大火气干嘛呢?<br>你不也在做MS的忠实用户吗?!你要做的什么破软件不也是要在WINDOWS下运行,舔MS的<br>屁股吗?有种开发一套DUDUCAT OS出来看看啊!瞎牛B!![:D]<br> <br>duducat(2002-10-09 12:12) <br>白痴……只知道MS……<br> <br>duducat(2002-10-09 12:43) <br>干吗让我开发os??笑死人了……<br>我又不是搞电脑的,也不需要靠它来赚钱谋生……<br>终于知道中国的IT业技术水平为什么这么低,原来是有一些猪头加奴隶充实在当中……<br>另外,我是人不是牛,人为什么要和牛作比较了,弱智……<br>做人不知道廉耻,就猪狗不如了……<br>什么都不知道,还这么神气……佩服佩服呀<br>哈哈哈哈哈哈哈!!!<br>天下真是无其不有……哈哈哈哈哈哈<br><br>to kcahcn<br>要讨论技术问题的,以后再跟你联系吧!<br> <br>yyk518(2002-10-09 16:19) <br>哦?你不是牛?可我怎么看你都比牛还牛啊!也许,是牛的后代也说不定,哈哈哈<br>你既然不是搞电脑的,又在这里瞎起什么哄!<br>知道MS没什么不好吧?!还“中国的IT”呢,谈到IT,不知道MS行吗?蠢猪!!!<br>呀,别生气啊!竟把猪比作了你(猪听见了可要生气了)<br>&gt;&gt;什么都不知道,还这么神气 <br>究竟是谁神气了?初出茅庐就不知天高地厚,连MS都不放在眼里了!如果中国人真的能<br>做出超越MS的软件,我当然非常高兴!但问题是,我们与MS的差距还很大,所以我们必需<br>好好向人家学习,多做些有益的事!不要两眼向天的走路,那样,你迟早会摔死的!<br> <br>duducat(2002-10-09 17:01) <br>做人不知道廉耻,就猪狗不如了……<br>什么都不知道,还这么神气……佩服佩服呀<br>哈哈哈哈哈哈哈!!!<br>天下真是无其不有……哈哈哈哈哈哈<br><br> <br>duducat(2002-10-09 18:11) <br>教教你吧……人不可有傲气,但不能无傲骨……能者为师<br>不过你属牛的,跟你说了也不懂,反正是对牛弹琴……<br>一副奴才像!不过MS好喜欢你的啦,觉得你好哟好可爱哟,呆会买糖给你吃!<br>(旁白:然后高呼打倒unix,Linux,Java……他们牛个屁呀,能玩服务器,能跨平台嘛?……<br> &nbsp;嘻嘻,都不如我的MS牛牛牛牛牛(省略5万字)……没有想到太高兴,碰了石头,最后“扑哧”<br> &nbsp;摔了个狗啃屎……5555555道:“MS,MS,……救救我!!他们说你坏话了,<br> &nbsp;我要你打他们的小屁股……”然后奋力举起MS掉在粪坑黑乎乎糖,<br> &nbsp; 叫道:“MS的糖是世界最香的糖啦……”, &nbsp;咬了起来。没想到却是个屁,<br> &nbsp; 还得意的叫道,“MS的屁也是最世界最最香的”……)<br>当然领导也很喜欢你这种牛了,帮着擦擦皮鞋,拍拍马屁,<br>赏你个吃“世界上最香的屁”吃吃……哈哈哈哈哈<br>干吗学电脑了,这又不会那也不会编,又要冒充IT人士,这到没有什么!(人各有所长)<br>可恶的是还专门打击比那些比你懂得多的人,心理寻思(他会那么多有啥用?<br>能比XX强嘛?能牛过XX吗?再厉害也不过是个中国人罢了……嘻嘻,<br>到最后还不如我嘴皮子1/100功效了……)<br>…………<br>俺心地善良,以后谁做了大领导一定推荐你这头牛去去拎拎皮鞋哟,呵呵!<br>编程就免了(即没有创意,又不肯向别人学习……)<br>哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈<br>…………<br>to 其他各位,对不起了,浪费你们的时间了……<br>非技术问题,到此为止!<br> <br>kcahcn(2002-10-10 08:06) <br>对于 system process “系统进程“要先设置SeDebugPrivilege才能用OpenProcess。<br>飞到这儿: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q131065<br>用这个方法 对 System Idle Process好像也没有用!!!<br>TaskManager,Pview 调用的是NtQuerySystemInformation所以没出现这个问题。<br>我用了那个函数(服务)果然没问题。可以得到System Idle Process所占的内存 (20kb WinXP)。<br>更多资料关于NtQuerySystemInformation请参考&quot;Windows Nt/2000 本机API&quot;。<br>关于CPU的占用率可以用GetProcessTimes 。(用Native API 也可以)<br>http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3816527f.149304919%40nntp.cts.com<br><br>看 : http://groups.google.com/groups?q=GetProcessTimes+CPU&ie=UTF-8&oe=UTF-8&hl=en&btnG=Google+Search<br>-----<br>CIONO1<br> <br>yyk518(2002-10-10 08:32) <br>TO duducat:<br>呵呵,没想到我随意说说,竟把这头笨牛给惹疯了,前言不搭后语,牛B哄哄地拉了一大堆<br>牛屎,哈哈哈,我看你不但瞎牛还很蠢,是即有牛的基因又有猪的血统,莫不是猪牛杂交<br>货?[:D][:D][:D]<br> <br>duducat(2002-10-10 12:37) <br>垃圾就是垃圾,呵呵,从里到外都是的……<br>……<br>to kcahcn <br>thanx!我说这些问题去年其实已经解决了……只是想讨论一下还有没有别的更好方法!<br>小日本的Processwalker(免费)<br>http://www001.upp.so-net.ne.jp/yamashita/<br>中还实现了其他很多有用的功能,如:进程拥有的特权之类。这些没有实现得了<br>所以找你的……<br>交个朋友吧,有空来我这里玩……,呵呵<br>代我向你妹妹问好……:)<br> <br>duducat(2002-10-10 21:21) <br>to gztoms<br>把分加给kcahcnkcahcn,他比我大方……<br><br>to kcahcn 再见了……希望以后还有机会跟你联系!我已经把它翻译成Delphi……<br>我用的不是这个函数!不过我现在有点喜欢NTQuerySystemInformation了!虽然它<br>存在不稳定因素:P<br><br>#include &lt;windows.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br><br>#ifndef STATUS_INFO_LENGTH_MISMATCH<br>#define STATUS_INFO_LENGTH_MISMATCH &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;((DWORD &nbsp; )0xC0000004L)<br>#endif<br><br>typedef struct<br>{<br> &nbsp; FILETIME ftCreationTime;<br> &nbsp; DWORD dwUnknown1;<br> &nbsp; DWORD dwStartAddress;<br> &nbsp; DWORD dwOwningPID;<br> &nbsp; DWORD dwThreadID;<br> &nbsp; DWORD dwCurrentPriority;<br> &nbsp; DWORD dwBasePriority;<br> &nbsp; DWORD dwContextSwitches;<br> &nbsp; DWORD dwThreadState;<br> &nbsp; DWORD dwWaitReason;<br> &nbsp; DWORD dwUnknown2[5];<br>} THREADINFO, *PTHREADINFO;<br><br>#pragma warning( disable:4200 ) // Zero sized array<br>typedef struct<br>{<br> &nbsp; DWORD dwRelativeOffset; &nbsp; //相对偏移量<br> &nbsp; DWORD dwThreadCount; &nbsp; &nbsp; &nbsp;//线程数目<br> &nbsp; DWORD dwUnknown1[6];<br> &nbsp; FILETIME pfCreateTime; <br> &nbsp; DWORD dwUnknown2[5];<br> &nbsp; WCHAR* pszProcessName; &nbsp; &nbsp;//不带路径的名称<br> &nbsp; DWORD dwBasePriority; &nbsp; &nbsp; //优先级 <br> &nbsp; DWORD dwProcessID; &nbsp; &nbsp; &nbsp; &nbsp;//进程ID<br> &nbsp; DWORD dwParentProcessID; &nbsp;//父进程ID<br> &nbsp; DWORD dwHandleCount; &nbsp; &nbsp; &nbsp;//句柄数目<br> &nbsp; DWORD dwUnknown3;<br> &nbsp; DWORD dwUnknown4;<br> &nbsp; DWORD dwVirtualBytesPeak;<br> &nbsp; DWORD dwTotalVirtualBytes;<br> &nbsp; DWORD dwPageFaults;<br> &nbsp; DWORD dwWorkingSetPeak; &nbsp; <br> &nbsp; DWORD dwTotalWorkingSet; &nbsp; &nbsp; &nbsp; //占用物理内存大小 &nbsp;<br> &nbsp; DWORD dwPeakPagedPoolUsagePages;<br> &nbsp; DWORD dwTotalPagedPoolUsagePages;<br> &nbsp; DWORD dwPeakNonPagedPoolUsagePages;<br> &nbsp; DWORD dwTotalNonPagedPoolUsagePages;<br> &nbsp; DWORD dwPageFileBytesPeak;<br> &nbsp; DWORD dwPrivateBytes;<br> &nbsp; DWORD dwPageFileBytes;<br> &nbsp; DWORD dwUnknown7[4];<br> &nbsp; THREADINFO ti[0];<br>} _PROCESSINFO, *PPROCESSINFO;<br>#pragma warning( default:4200 )<br><br>DWORD (__stdcall *NtQuerySystemInformation )(ULONG,PVOID,ULONG,ULONG);<br><br>void ShowPI(void)<br>{<br> &nbsp; PBYTE pbyInfo = NULL;<br> &nbsp; PPROCESSINFO pProcessInfo;<br> &nbsp; DWORD dwSize = 0x4000;<br> &nbsp; WCHAR *pname;<br><br> &nbsp; if (!NtQuerySystemInformation)<br> &nbsp; &nbsp; &nbsp;NtQuerySystemInformation=(DWORD (__stdcall*)(ULONG,PVOID,ULONG,ULONG))<br><br>GetProcAddress(GetModuleHandle(&quot;ntdll.dll&quot;),&quot;NtQuerySystemInformation&quot;);<br><br> &nbsp; pbyInfo=(PBYTE) malloc(dwSize);<br><br> &nbsp; if (pbyInfo)<br> &nbsp; {<br> &nbsp; &nbsp; &nbsp;for(;;)<br> &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; memset(pbyInfo,0,dwSize);<br><br><br>if(NtQuerySystemInformation(5,pbyInfo,dwSize,0)!=STATUS_INFO_LENGTH_MISMATCH<br>)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; dwSize += 0x1000;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; pbyInfo=(PBYTE) realloc(pbyInfo,dwSize);<br> &nbsp; &nbsp; &nbsp;}<br><br> &nbsp; &nbsp; &nbsp;pProcessInfo = ( PPROCESSINFO ) pbyInfo;<br><br> &nbsp; &nbsp; &nbsp;for(;;)<br> &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; &nbsp; &nbsp; pname=pProcessInfo-&gt;pszProcessName;<br><br> &nbsp; &nbsp; &nbsp; &nbsp; if (!pname)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pname=(L&quot;Idle&quot;);<br><br> &nbsp; &nbsp; &nbsp; &nbsp; printf(&quot;%-40ls %-12lu %12luK/n&quot;,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pname,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pProcessInfo-&gt;dwProcessID,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pProcessInfo-&gt;dwTotalWorkingSet/1024ul<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br><br> &nbsp; &nbsp; &nbsp; &nbsp; if ( pProcessInfo-&gt;dwRelativeOffset == 0 )<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;<br><br><br>pProcessInfo=(PPROCESSINFO)((PBYTE)pProcessInfo+pProcessInfo-&gt;dwRelativeOffset);<br> &nbsp; &nbsp; &nbsp;}<br><br> &nbsp; &nbsp; &nbsp;free( pbyInfo );<br> &nbsp; } <br>}<br><br>int main(void)<br>{<br> &nbsp; ShowPI();<br> &nbsp; getchar();<br> &nbsp; return 0;<br>}<br><br> <br>duducat(2002-10-10 21:28) <br>to gztoms <br>9X的自己研究吧……实在不知道,明年再联系!<br>to kcahcn <br>人生无常,唯朋友最值得珍惜……<br> <br>kcahcn(2002-10-10 22:17) <br>to duducat : Thanks alot;<br>我会把我写的代码(经过改进后)发到你的邮箱。(还要一段时间)<br>NativeAPI有很多东西可以研究。很多人在研究。多多看看Nebbett写的那本书。<br>有什么冬冬告诉我。[:D]<br>to gztoms :我不是为了积分而回答。我不需要积分。Knowledge is free .<br><br>CIONO1<br> <br>gztoms(2002-10-11 15:43) <br>谢谢kcahcn,duducat<br> <br><br>duducat-50,kcahcn-150,的回答最终被接受。
 
前面的搞了半天,但是取不到我需要的DLLHOSE.EXE,显示仍为0,<br>后面的C看不懂
 
使用MiTeC System Information Component Suite控件,里面MiTeC_ProcessList控件搞定这一切。<br>贴一段它DEMO里的代码你看:<br>unit Main;<br><br>interface<br><br>uses<br> &nbsp;Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,<br> &nbsp;Dialogs, MSI_Processes, ComCtrls, ExtCtrls, StdCtrls, MSI_Common;<br><br>type<br> &nbsp;Twnd_Main = class(TForm)<br> &nbsp; &nbsp;List: TListView;<br> &nbsp; &nbsp;pTitle: TPanel;<br> &nbsp; &nbsp;Image1: TImage;<br> &nbsp; &nbsp;Bevel1: TBevel;<br> &nbsp; &nbsp;bRefresh: TButton;<br> &nbsp; &nbsp;bSave: TButton;<br> &nbsp; &nbsp;bClose: TButton;<br> &nbsp; &nbsp;Label1: TLabel;<br> &nbsp; &nbsp;Label2: TLabel;<br> &nbsp; &nbsp;eName: TEdit;<br> &nbsp; &nbsp;ePri: TEdit;<br> &nbsp; &nbsp;sd: TSaveDialog;<br> &nbsp; &nbsp;ProcList: TMiTeC_ProcessList;<br> &nbsp; &nbsp;procedure FormCreate(Sender: TObject);<br> &nbsp; &nbsp;procedure ListCompare(Sender: TObject; Item1, Item2: TListItem;<br> &nbsp; &nbsp; &nbsp;Data: Integer; var Compare: Integer);<br> &nbsp; &nbsp;procedure ListColumnClick(Sender: TObject; Column: TListColumn);<br> &nbsp; &nbsp;procedure ListAdvancedCustomDrawItem(Sender: TCustomListView;<br> &nbsp; &nbsp; &nbsp;Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;<br> &nbsp; &nbsp; &nbsp;var DefaultDraw: Boolean);<br> &nbsp; &nbsp;procedure ListAdvancedCustomDrawSubItem(Sender: TCustomListView;<br> &nbsp; &nbsp; &nbsp;Item: TListItem; SubItem: Integer; State: TCustomDrawState;<br> &nbsp; &nbsp; &nbsp;Stage: TCustomDrawStage; var DefaultDraw: Boolean);<br> &nbsp; &nbsp;procedure TimerTimer(Sender: TObject);<br> &nbsp; &nbsp;procedure bRefreshClick(Sender: TObject);<br> &nbsp; &nbsp;procedure bCloseClick(Sender: TObject);<br> &nbsp; &nbsp;procedure ListSelectItem(Sender: TObject; Item: TListItem;<br> &nbsp; &nbsp; &nbsp;Selected: Boolean);<br> &nbsp; &nbsp;procedure bSaveClick(Sender: TObject);<br> &nbsp;private<br> &nbsp;public<br> &nbsp; &nbsp;procedure RefreshData;<br> &nbsp;end;<br><br>var<br> &nbsp;wnd_Main: Twnd_Main;<br><br>implementation<br><br>uses MiTeC_CtrlRtns, MiTeC_Datetime;<br><br>{$R *.dfm}<br><br>procedure Twnd_Main.FormCreate(Sender: TObject);<br>begin<br> &nbsp;if Win32Platform&lt;&gt;VER_PLATFORM_WIN32_NT then begin<br> &nbsp; &nbsp;List.Columns[2].Caption:='Threads';<br> &nbsp; &nbsp;List.Columns[3].Caption:='Usage';<br> &nbsp;end;<br> &nbsp;RefreshData;<br>end;<br><br>procedure Twnd_Main.RefreshData;<br>var<br> &nbsp;i: Integer;<br>begin<br> &nbsp;with ProcList do<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;List.Items.BeginUpdate;<br> &nbsp; &nbsp; &nbsp;List.Items.Clear;<br> &nbsp; &nbsp; &nbsp;//Screen.Cursor:=crHourglass;<br> &nbsp; &nbsp; &nbsp;RefreshData;<br> &nbsp; &nbsp; &nbsp;for i:=0 to ProcessCount-1 do<br> &nbsp; &nbsp; &nbsp; &nbsp;with List.Items.Add do begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Caption:=Processes.Name;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Win32Platform&lt;&gt;VER_PLATFORM_WIN32_NT then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(Format('%x',[Processes.PID]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(Format('%d',[Processes.ThreadCount]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(Format('%d',[Processes.Usage]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end else begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(Format('%d',[Processes.PID]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(FormatSeconds((Processes.UserTime.QuadPart+Processes.KernelTime.QuadPart)/10000000,True,False,True));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SubItems.Add(Format('%d KB',[Processes.VMCounters.WorkingSetSize div 1024]));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;List.Items.EndUpdate;<br> &nbsp; &nbsp; &nbsp;pTitle.Caption:=Format(' &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; %d processes',[List.Items.Count]);<br> &nbsp; &nbsp; &nbsp;//Screen.Cursor:=crDefault;<br> &nbsp; &nbsp;end;<br>end;<br><br>procedure Twnd_Main.ListCompare(Sender: TObject; Item1, Item2: TListItem;<br> &nbsp;Data: Integer; var Compare: Integer);<br>begin<br> &nbsp;Compare:=ListView_CustomSort(Item1,Item2,ListView_SortColumn);<br> &nbsp;if ListView_SortDescending then<br> &nbsp; &nbsp;Compare:=-Compare;<br>end;<br><br>procedure Twnd_Main.ListColumnClick(Sender: TObject; Column: TListColumn);<br>begin<br> &nbsp;TListView(Sender).SortType:=stNone;<br> &nbsp;if Column.Index&lt;&gt;ListView_SortColumn then begin<br> &nbsp; &nbsp;ListView_SortColumn:=Column.Index;<br> &nbsp; &nbsp;ListView_SortDescending:=False;<br> &nbsp;end else<br> &nbsp; &nbsp;ListView_SortDescending:=not ListView_SortDescending;<br> &nbsp;TListView(Sender).SortType:=stText;<br>end;<br><br>procedure Twnd_Main.ListAdvancedCustomDrawItem(Sender: TCustomListView;<br> &nbsp;Item: TListItem; State: TCustomDrawState; Stage: TCustomDrawStage;<br> &nbsp;var DefaultDraw: Boolean);<br>begin<br> &nbsp;if ListView_SortColumn=0 then<br> &nbsp; &nbsp;Sender.Canvas.Brush.Color:=clInfoBk<br> &nbsp;else<br> &nbsp; &nbsp;Sender.Canvas.Brush.Color:=clWhite<br>end;<br><br>procedure Twnd_Main.ListAdvancedCustomDrawSubItem(Sender: TCustomListView;<br> &nbsp;Item: TListItem; SubItem: Integer; State: TCustomDrawState;<br> &nbsp;Stage: TCustomDrawStage; var DefaultDraw: Boolean);<br>begin<br> &nbsp;if ListView_SortColumn=SubItem then<br> &nbsp; &nbsp;Sender.Canvas.Brush.Color:=clInfoBk<br> &nbsp;else<br> &nbsp; &nbsp;Sender.Canvas.Brush.Color:=clWhite<br>end;<br><br>procedure Twnd_Main.TimerTimer(Sender: TObject);<br>begin<br> &nbsp;RefreshData;<br>end;<br><br>procedure Twnd_Main.bRefreshClick(Sender: TObject);<br>begin<br> &nbsp;RefreshData;<br>end;<br><br>procedure Twnd_Main.bCloseClick(Sender: TObject);<br>begin<br> &nbsp;Close;<br>end;<br><br>procedure Twnd_Main.ListSelectItem(Sender: TObject; Item: TListItem;<br> &nbsp;Selected: Boolean);<br>var<br> &nbsp;idx: Integer;<br> &nbsp;pid: DWORD;<br>begin<br> &nbsp;idx:=-1;<br> &nbsp;if Assigned(Item) and Selected then begin<br> &nbsp; &nbsp;if Win32Platform&lt;&gt;VER_PLATFORM_WIN32_NT then<br> &nbsp; &nbsp; &nbsp;pid:=StrToInt('$'+Item.SubItems[0])<br> &nbsp; &nbsp;else<br> &nbsp; &nbsp; &nbsp;pid:=StrToInt(Item.SubItems[0]);<br> &nbsp; &nbsp;idx:=ProcList.FindProcess(pid);<br> &nbsp; &nbsp;if idx&lt;&gt;-1 then begin<br> &nbsp; &nbsp; &nbsp;eName.Text:=ProcList.Processes[idx].ImageName;<br> &nbsp; &nbsp; &nbsp;ePri.Text:=Format('%d',[ProcList.Processes[idx].Priority]);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br> &nbsp;if idx=-1 then begin<br> &nbsp; &nbsp;eName.Text:='';<br> &nbsp; &nbsp;ePri.Text:='';<br> &nbsp;end;<br>end;<br><br>procedure Twnd_Main.bSaveClick(Sender: TObject);<br>begin<br> &nbsp;if sd.Execute then<br> &nbsp; &nbsp;ProcList.SaveToStorage(sd.FileName);<br>end;<br><br>end.
 
下载了可能是试用版的,有正式版的吗<br>只看到两个控件,没有 MiTeC_ProcessList
 
http://www.fixdown.com/soft/24572.asp?fixdown.com=gdteldowns
 
后退
顶部