- #include <windows.h>
- #include <TCHAR.h>
- #include <tlhelp32.h>
- #include <locale.h>
- #include <stdio.h>
- int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int nCmdShow)
- {
- AllocConsole();//分配控制台
- ::freopen("CONOUT$", "w", stdout);
- PROCESSENTRY32 pe32;
- pe32.dwSize=sizeof(pe32);
- HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- BOOL bMore=Process32First(hProcessSnap,&pe32);
- setlocale(LC_ALL, "chs");
- while(bMore)
- {
- _tprintf(TEXT("进程名称:%s\n"),pe32.szExeFile);
- _tprintf(TEXT("进程ID:%u \n\n"),pe32.th32ProcessID);
- bMore=Process32Next(hProcessSnap,&pe32);
- }
- CloseHandle(hProcessSnap);
- Sleep(3000); //睡眠3秒钟
- FreeConsole(); //关闭释放控制台
- return 0;
- }
或:
- PROCESSENTRY32 pe32;
- pe32.dwSize=sizeof(pe32);
- HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- BOOL bMore=Process32First(hProcessSnap,&pe32);
- setlocale(LC_ALL, "chs");
- TCHAR str[256*sizeof(TCHAR)];
- while(bMore)
- {
- _stprintf(str, TEXT("进程名称:%s\n进程ID:%u \n\n"),pe32.szExeFile,pe32.th32ProcessID);
- OutputDebugString(str);
- bMore=Process32Next(hProcessSnap,&pe32);
- }
- CloseHandle(hProcessSnap);
- #include <windows.h>
- #include <TCHAR.h>
- #include <tlhelp32.h>
- #include <locale.h>
- #include <stdio.h>
- int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int nCmdShow)
- {
- AllocConsole();//分配控制台
- ::freopen("CONOUT$", "w", stdout);
- PROCESSENTRY32 pe32;
- pe32.dwSize=sizeof(pe32);
- HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- BOOL bMore=Process32First(hProcessSnap,&pe32);
- setlocale(LC_ALL, "chs");
- while(bMore)
- {
- _tprintf(TEXT("进程名称:%s\n"),pe32.szExeFile);
- _tprintf(TEXT("进程ID:%u \n\n"),pe32.th32ProcessID);
- bMore=Process32Next(hProcessSnap,&pe32);
- }
- CloseHandle(hProcessSnap);
- Sleep(3000); //睡眠3秒钟
- FreeConsole(); //关闭释放控制台
- return 0;
- }
或:
- PROCESSENTRY32 pe32;
- pe32.dwSize=sizeof(pe32);
- HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
- BOOL bMore=Process32First(hProcessSnap,&pe32);
- setlocale(LC_ALL, "chs");
- TCHAR str[256*sizeof(TCHAR)];
- while(bMore)
- {
- _stprintf(str, TEXT("进程名称:%s\n进程ID:%u \n\n"),pe32.szExeFile,pe32.th32ProcessID);
- OutputDebugString(str);
- bMore=Process32Next(hProcessSnap,&pe32);
- }
- CloseHandle(hProcessSnap);
本文转自 xcf007 51CTO博客,原文链接:http://blog.51cto.com/xcf007/752017,如需转载请自行联系原作者