Simple Process Viewer

The ProcessViewer is a very simple console application process viewer that displays the information about the processes that are currently executing in the memory. Here's an example of what the running applications displays.

While the overall scope of the application may be narrow, the code does illustrate how to use of Tool Help Library provided by Microsoft in order to obtain vital information about running processes. Below is the salient code for this purpose.

Note that specifically the application makes use of the process functions Process32First and Process32Next to find all the running processes in the system.

void CProcessViewerDlg::ShowProcessData()
{
 // Get the snapshot of the system

 hSnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);

 PROCESSENTRY32 pEntry;

 pEntry.dwSize = sizeof(pEntry);

 //Buffer for Process Info
 char szProcessInfo[255];

 /Get first process
 Process32First(hSnapShot, &pEntry);

 //Iterate thru all processes

 while(1)
 {
  BOOL hRes=Process32Next (hSnapShot,&pEntry);

  if(hRes==FALSE)
   break;

  sprintf(szProcessInfo,"%d",pEntry.th32ProcessID );

  m_list.InsertItem(0,pEntry.szExeFile);
  m_list.SetItemText(0,0,pEntry.szExeFile);
  m_list.SetItemText(0,1,szProcessInfo);

  sprintf(szProcessInfo,"%d",pEntry.cntThreads );
  m_list.SetItemText(0,2,szProcessInfo);

  sprintf(szProcessInfo,"%d",pEntry.th32ParentProcessID);
  m_list.SetItemText(0,3,szProcessInfo);

  sprintf(szProcessInfo,"%d",pEntry.pcPriClassBase );
  m_list.SetItemText(0,4,szProcessInfo);
 }
}

Downloads

Download demo source and demo - 14 Kb