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


Comments

  • this error is coming while Building project

    Posted by madhusudhanv on 03/07/2006 05:25am

    The compilation is done successfully , but building this error is coming ??? --------------------Configuration: ProcessViewer - Win32 Debug-------------------- Compiling... TaskManagerEx.cpp c:\process\taskmanager1\taskmanagerex\taskmanagerex\taskmanagerex.cpp(6) : fatal error C1083: Cannot open include file: 'LoadDll.h': No such file or directory Error executing cl.exe. ProcessViewer.exe - 1 error(s), 0 warning(s)

    Reply
  • How can I find out...

    Posted by Legacy on 02/23/2004 12:00am

    Originally posted by: Punga

    If I have only PID how can I find out if the current process works or not? I can't get HANDLE of some processes(There are no sufficient rights).

    Reply
  • startup manager

    Posted by Legacy on 06/04/2003 12:00am

    Originally posted by: gaurav

    How can i know which are the application currently installed in startup Manager.How can i access them with win32 program with their path and icon.

    Reply
  • I have a problem while linking the demo code?

    Posted by Legacy on 04/25/2003 12:00am

    Originally posted by: Vijaya

    Hello,

    I downloaded the demo files and tried to build the processviewer.exe. I get the following error.

    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
    nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
    libcd.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/ProcessViewer.exe : fatal error LNK1120: 3 unresolved externals
    Error executing link.exe.

    ProcessViewer.exe - 4 error(s), 0 warning(s)

    What files am I missing?

    Thanks,
    Vijaya

    Reply
  • How I can close any program.

    Posted by Legacy on 04/09/2003 12:00am

    Originally posted by: Rehan Shaukat

    Hello,

    I want to close any programm running on window. please help me.

    THanx in advance.
    Rehan

    Reply
  • how to get my installed software's name and its (exe) filename

    Posted by Legacy on 09/12/2002 12:00am

    Originally posted by: zhang

    How do I get my computer's installed-softwares'name
    and its (exe)filename before executing the software,
    such as,I have installed office2000 software, but I
    can't know how to get its (exe)filename and its fullpath
    I need it very much

    Reply
  • How can u view window captions like in ctrl-alt-dlt

    Posted by Legacy on 07/24/2002 12:00am

    Originally posted by: jimmy

    how can u view window captions like in ctrl-alt-dlt.
    please e-mail me it would be much appreciated

    Reply
  • cntUsage - How can I display CPU - Usage?

    Posted by Legacy on 07/04/2002 12:00am

    Originally posted by: pat

    Hey!

    so you written the program, but why you did not implement the cpu usage? can you make an update?

    or can you tell me why the pEntry.cntUsage returns 0 ?

    well i think you mastered the problem, i plea you to share your experience.

    thx pat.

    Reply
  • ProcessViewer.exe- Entry Point Not Found

    Posted by Legacy on 06/03/2002 12:00am

    Originally posted by: mar

    When I tried to run it, the following error message
    appears. " The procedure entry point Process32First could
    not be located in the dynamic link library KERNEL32.dll "

    Please Help !!!

    I don't know what to do...

    Reply
  • tic.exe and Process32First ???

    Posted by Legacy on 02/05/2002 12:00am

    Originally posted by: Concerned Individual

    Hello. I am in need of some advice/help. We are running a small office with a server using WindowsNT (Service Pack 4, Version 6a). Lately, we have noticed an error message pop-up each time after a fresh boot. The message reads as follows:

    "The prodcedure entry point Process32First could not be located in the dynamic link library Kernel32.dll."

    Would you have any suggestions for someone who is not too familiar with computer coding? Would adding this .dll file solve my problems? I would be able to follow directions if given a step-by-step instructions. Thank you.

    Sincerely,

    Bert

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Mobile devices, social business apps, and business analytics are converging with the Cloud to create the most substantial changes in technology since the Internet revolution. Businesses have to change the way they think and operate, and with rising budgets for technology, they need someone to provide the services that will keep them competitive in this environment. Learn more about the important technology trends you need to stay on top of to ensure your business doesn't get left behind.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds