This article illustrates the implementation method of C + + based CreateToolhelp32Snapshot acquisition system process. Share to everyone for your reference. The specific methods are as follows:
GetWinProcess.cpp: Defines the entry point for a console application.
//
#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 ("[Process name]:%ws\n", pe32.szexefile);
printf ("[pid]:%d\n\n", pe32.th32processid);
BRet = Process32Next (Hprocesssnap, &pe32);
}
:: CloseHandle (HPROCESSSNAP);//Often forget this sentence return
0;
I hope this article will help you with the C + + program design.