#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>#include <psapi.h>
#pragma comment (lib,"psapi.lib")
BOOL test()
{
HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if(SnapShot==NULL)
{
return FALSE;
}
PROCESSENTRY32 ProcessInfo;//声明进程信息变量
ProcessInfo.dwSize=sizeof(ProcessInfo);//设置ProcessInfo的大小
//返回系统中第一个进程的信息
BOOL Status=Process32First(SnapShot,&ProcessInfo);
while(Status)
{
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,TRUE,ProcessInfo.th32ProcessID);
if(hProcess)
{
SetProcessWorkingSetSize(hProcess,0,0);
//内存整理
EmptyWorkingSet(hProcess);
CloseHandle(hProcess);
}
printf("%s/n",ProcessInfo.szExeFile);
//获取下一个进程的信息
Status=Process32Next(SnapShot,&ProcessInfo);
}
return TRUE;
}
int main()
{
test();
return 0;
}