#include <psapi.h>
DWORD num_processes;
DWORD process_ids[1024];
EnumProcesses(process_ids, sizeof(process_ids), &num_processes);
//遍历进程
for (int i = 0; i < num_processes; i++)
{
//根据进程ID获取句柄
HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, 0,
process_ids[i]);
//通过句柄获取进程文件名
char File_name[300];
if (GetModuleFileNameExA(process, NULL, File_name, sizeof(File_name)))
cout << File_name << endl;
}