/*
* 檔案名稱:EnumProcess.c
* 用途:枚舉進程
* 編程環境:WinXP SP2+CL 8.0
* 完成日期: 2006.2 Ver 0.01
* 作者: 88250
* 連絡方式: E-mail: DL88250@gmail.com QQ:845765
*/
#include <stdio.h>
#include <windows.h>
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
int main(void)
{
DWORD processid[1024], pBytesReturned[1024], processSum, i;
HANDLE hProcess;
HMODULE hModule;
char path[MAX_PATH] = "", temp[256];
printf("ShowProcessPath with [Process Status API] ");
EnumProcesses(processid, sizeof(processid), pBytesReturned);
processSum = *pBytesReturned / sizeof(DWORD);
for (i = 0; i < processSum; i++){
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processid[i]);
if (hProcess){
EnumProcessModules(hProcess, &hModule, sizeof(hModule), pBytesReturned);
GetModuleFileNameEx(hProcess, hModule, path, sizeof(path));
GetShortPathName(path, path, 256);
itoa(processid[i], temp, 10);
printf("%s --- %s ", path, temp);
}else{
printf("Failed!!! "); // 許可權不夠,不能訪問有的進程
}
}
CloseHandle(hProcess);
CloseHandle(hModule);
itoa(processSum, temp, 10);
printf(" Process Count:%s ", temp);
return 0;
}