to gztoms<br>把分加给kcahcnkcahcn,他比我大方……<br><br>to kcahcn 再见了……希望以后还有机会跟你联系!我已经把它翻译成Delphi……<br>我用的不是这个函数!不过我现在有点喜欢NTQuerySystemInformation了!虽然它<br>存在不稳定因素:P<br><br>#include <windows.h><br>#include <stdio.h><br>#include <stdlib.h><br><br>#ifndef STATUS_INFO_LENGTH_MISMATCH<br>#define STATUS_INFO_LENGTH_MISMATCH ((DWORD )0xC0000004L)<br>#endif<br><br>typedef struct<br>{<br> FILETIME ftCreationTime;<br> DWORD dwUnknown1;<br> DWORD dwStartAddress;<br> DWORD dwOwningPID;<br> DWORD dwThreadID;<br> DWORD dwCurrentPriority;<br> DWORD dwBasePriority;<br> DWORD dwContextSwitches;<br> DWORD dwThreadState;<br> DWORD dwWaitReason;<br> DWORD dwUnknown2[5];<br>} THREADINFO, *PTHREADINFO;<br><br>#pragma warning( disable:4200 ) // Zero sized array<br>typedef struct<br>{<br> DWORD dwRelativeOffset; //相对偏移量<br> DWORD dwThreadCount; //线程数目<br> DWORD dwUnknown1[6];<br> FILETIME pfCreateTime; <br> DWORD dwUnknown2[5];<br> WCHAR* pszProcessName; //不带路径的名称<br> DWORD dwBasePriority; //优先级 <br> DWORD dwProcessID; //进程ID<br> DWORD dwParentProcessID; //父进程ID<br> DWORD dwHandleCount; //句柄数目<br> DWORD dwUnknown3;<br> DWORD dwUnknown4;<br> DWORD dwVirtualBytesPeak;<br> DWORD dwTotalVirtualBytes;<br> DWORD dwPageFaults;<br> DWORD dwWorkingSetPeak; <br> DWORD dwTotalWorkingSet; //占用物理内存大小 <br> DWORD dwPeakPagedPoolUsagePages;<br> DWORD dwTotalPagedPoolUsagePages;<br> DWORD dwPeakNonPagedPoolUsagePages;<br> DWORD dwTotalNonPagedPoolUsagePages;<br> DWORD dwPageFileBytesPeak;<br> DWORD dwPrivateBytes;<br> DWORD dwPageFileBytes;<br> DWORD dwUnknown7[4];<br> 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> PBYTE pbyInfo = NULL;<br> PPROCESSINFO pProcessInfo;<br> DWORD dwSize = 0x4000;<br> WCHAR *pname;<br><br> if (!NtQuerySystemInformation)<br> NtQuerySystemInformation=(DWORD (__stdcall*)(ULONG,PVOID,ULONG,ULONG))<br><br>GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation");<br><br> pbyInfo=(PBYTE) malloc(dwSize);<br><br> if (pbyInfo)<br> {<br> for(;
<br> {<br> memset(pbyInfo,0,dwSize);<br><br><br>if(NtQuerySystemInformation(5,pbyInfo,dwSize,0)!=STATUS_INFO_LENGTH_MISMATCH<br>)<br> break;<br><br> dwSize += 0x1000;<br><br> pbyInfo=(PBYTE) realloc(pbyInfo,dwSize);<br> }<br><br> pProcessInfo = ( PPROCESSINFO ) pbyInfo;<br><br> for(;
<br> {<br> pname=pProcessInfo->pszProcessName;<br><br> if (!pname)<br> pname=(L"Idle");<br><br> printf("%-40ls %-12lu %12luK/n",<br> pname,<br> pProcessInfo->dwProcessID,<br> pProcessInfo->dwTotalWorkingSet/1024ul<br>  
;<br><br> if ( pProcessInfo->dwRelativeOffset == 0 )<br> break;<br><br><br>pProcessInfo=(PPROCESSINFO)((PBYTE)pProcessInfo+pProcessInfo->dwRelativeOffset);<br> }<br><br> free( pbyInfo );<br> } <br>}<br><br>int main(void)<br>{<br> ShowPI();<br> getchar();<br> return 0;<br>}<br>