C++

The VC implementation gets the currently running process


This article illustrates how the VC implementation captures the currently running process. Share with you for your reference. The specific implementation method is as follows:

#include <windows.h>
#include <tlhelp32.h>
#include <stdio.h>
int main(int argc,char* argv[])
{
PROCESSENTRY32 pe32;
//Define the size of the structure before you use it again
pe32.dwSize=sizeof(pe32);
//Take a snapshot of all the processes in the system
HANDLE hProcessSnap=::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if (hProcessSnap==INVALID_HANDLE_VALUE)
{
  printf("Create ToolHelp32Snaphhot Call fails !n");
  return -1;
}
BOOL bMore=::Process32First(hProcessSnap,&pe32);
while(bMore)
{
  printf(" Process name :%sn",pe32.szExeFile);
  printf(" process ID No. :%unn",pe32.th32ProcessID);
  bMore=::Process32Next(hProcessSnap,&pe32);
}
printf(" Don't forget to clear it out snapshot");
::CloseHandle(hProcessSnap);
return 0;
}

Hope that this article described the VC programming for you to help.