1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| #include "windows.h" #include "tlhelp32.h" #include "stdio.h" int main(int argc, char* argv[]) { PROCESSENTRY32 pe32; pe32.dwSize = sizeof(pe32); HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); if (hProcessSnap == INVALID_HANDLE_VALUE) { printf("CreateToolhelp32Snapshot 调用失败.\n"); return -1; } BOOL bMore = ::Process32First(hProcessSnap,&pe32); while (bMore) { printf("进程名称:%s\n",pe32.szExeFile); printf("进程ID:%u\n\n",pe32.th32ProcessID); bMore = ::Process32Next(hProcessSnap,&pe32); } ::CloseHandle(hProcessSnap); return 0; }
|