遍历系统进程
#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{1}quot;, "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;
}