C++ CreateToolhelp32Snapshot 获取系统进程
C++ CreateToolhelp32Snapshot 获取系统进程#include "stdafx.h"
#include <Windows.h>
#include <TlHelp32.h>
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (hProcessSnap == FALSE )
{
printf("CreateToolhelp32Snapshot error");
return -1;
}
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
BOOL bRet = Process32First(hProcessSnap, &pe32);
while (bRet)
{
printf(":%ws\n", pe32.szExeFile);
printf(":%d\n\n",pe32.th32ProcessID);
bRet = Process32Next(hProcessSnap, &pe32);
}
::CloseHandle(hProcessSnap); // 经常忘记这句
return 0;
}
页:
[1]