效果图
源码
#define _WIN32_WINNT 0x0601
#include
#include
#include
int main(int argc, PCHAR argv[]){
DWORD size = 1000 * sizeof(DWORD);
DWORD lpidProcess = VirtualAlloc(NULL, size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
PDWORD pid = lpidProcess;
//DWORD lpidProcess[4000] = { 0 };
DWORD num;
if (!lpidProcess){
printf("分配内存失败\n");
}
int a = 0;
if (EnumProcesses(lpidProcess,size, &num)){
printf("当前系统共有 %d 个进程:\n", num/4);
for (a = 0; a< num;a+=4){
printf("pid= %d", *(DWORD*)(lpidProcess + a));
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_QUERY_LIMITED_INFORMATION, FALSE, *(DWORD*)(lpidProcess + a));
if (hProcess){
DWORD length = MAX_PATH;
TCHAR ProcessName[MAX_PATH] = TEXT("<未知>");
QueryFullProcessImageName(hProcess, 0, ProcessName, &length);
printf(" lpExeName = %s\n", ProcessName);
} else{
printf("\n", GetLastError());
}
}
} else{
printf(" EnumProcess Error %d\n", GetLastError());
}
VirtualFree(lpidProcess, size, MEM_DECOMMIT);
getchar();
return 0;
}
网友评论