Click here to Skip to main content
Licence 
First Posted 4 Dec 2005
Views 47,534
Bookmarked 40 times

Advanced Task Manager in MFC

By | 4 Dec 2005 | Article
This article demonstrates how to create a Task Manager in MFC which lists all the processes running in the system along with their process details and version information.

Sample Image - AdvancedTaskManager.jpg

Introduction

This article demonstrates how to create a task manager using MFC. This task manager known as Advanced Task Manager will display extra information than a standard task manager, like the properties of a running executable and process details.

Background

The standard task manager available will show the details about running processes, but in some cases, we need to know the path of the executable from which the process is running, which is not available. This application will show the details of a process like the path from which it is executing, product name, product version etc.

Implementation

The design is simple here. There are three classes which perform the action. CProcessEnumerator is responsible for loading all NT processes. All these processes are loaded to a list control. CProcessViewer can provide information about a specified process, and CVersionViewer can provide information about a running executable.

The following code enumerates all the running processes on a WIN NT/2000 system:

//
BOOL CProcessEnumerator::EnumWinNTProcs( PROCENUMPROC lpProc, LPARAM lParam )
{
    LPDWORD        lpdwPIDs ;
    DWORD          dwSize, dwSize2, dwIndex ;
    HMODULE        hMod ;
    HANDLE         hProcess ;
    char           szFileName[ MAX_PATH ] ;
    ENUMINFOSTRUCT sInfo ;

    dwSize2 = 256 * sizeof( DWORD ) ;
    lpdwPIDs = NULL ;
    do
    {
        if( lpdwPIDs )
        {
            HeapFree( GetProcessHeap(), 0, lpdwPIDs ) ;
            dwSize2 *= 2 ;
        }
        lpdwPIDs = (LPDWORD)HeapAlloc( GetProcessHeap(), 0, dwSize2 );
        if( lpdwPIDs == NULL )
        {
            return FALSE ;
        }
        if( !m_lpfEnumProcesses( lpdwPIDs, dwSize2, &dwSize ) )
        {
            HeapFree( GetProcessHeap(), 0, lpdwPIDs ) ;
            return FALSE ;
        }
    }while( dwSize == dwSize2 ) ;
    
    dwSize /= sizeof( DWORD ) ;
    
    // Loop through each ProcID.
    for( dwIndex = 0 ; dwIndex < dwSize ; dwIndex++ )
    {
        szFileName[0] = 0 ;
        hProcess = OpenProcess(
            PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
            FALSE, lpdwPIDs[ dwIndex ] ) ;
        if( hProcess != NULL )
        {
            if( m_lpfEnumProcessModules( hProcess, &hMod,
                sizeof( hMod ), &dwSize2 ) )
            {
                // Get Full pathname:
                if( !m_lpfGetModuleFileNameEx( hProcess, hMod,
                    szFileName, sizeof( szFileName ) ) )
                {
                    szFileName[0] = 0 ;
                }
            }
            CloseHandle( hProcess ) ;
        }
        DWORD lastErr = GetLastError();
        if(!lpProc( lpdwPIDs[dwIndex], 0, szFileName, lParam))
            break ;
        if( _stricmp( szFileName+(strlen(szFileName)-9),
            "NTVDM.EXE")==0)
        {
            sInfo.dwPID = lpdwPIDs[dwIndex] ;
            sInfo.lpProc = lpProc ;
            sInfo.lParam = lParam ;
            sInfo.bEnd = FALSE ;
            try
            {
                m_lpfVDMEnumTaskWOWEx( lpdwPIDs[dwIndex],
                    (TASKENUMPROCEX) Enum16,
                    (LPARAM) &sInfo);
            }
            catch(...)
            {
                continue;
            }
            if(sInfo.bEnd)
                break ;
        }
    }
    
    HeapFree( GetProcessHeap(), 0, lpdwPIDs ) ;
    
    return TRUE ;
}


BOOL CProcessEnumerator::Enum16( 
                DWORD dwThreadId, 
                WORD hMod16, 
                WORD hTask16,
                PSZ pszModName, 
                PSZ pszFileName, 
                LPARAM lpUserDefined )
{
  BOOL bRet ;

  ENUMINFOSTRUCT *psInfo = (ENUMINFOSTRUCT *)lpUserDefined ;

  bRet = psInfo->lpProc( psInfo->dwPID, 
         hTask16, pszFileName, psInfo->lParam ) ;

  if(!bRet)
  {
     psInfo->bEnd = TRUE ;
  }

  return !bRet;
} 
//

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Madhu Raykar

Web Developer

India India

Member

I have been working in software industry for the past 5 years now. Enjoy working on complex and new technologies. Worked on Microsoft technologies Like VC++, COM, XML, SQL. Currently working on .Net, C#.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralСomment Pinmemberv.k.l.chr..by11:19 17 May '10  
GeneralPls help Pinmemberjinijinu22:46 16 Sep '08  
GeneralPls help Pinmemberjinijinu18:47 16 Sep '08  
GeneralFamilar UI PinmemberVasudevan Deepak Kumar18:24 30 Jul '07  
Generalapi Pinmemberbeto.ch0:58 30 Jan '06  
Generalhelp please... Pinmembertzvila23:35 22 Dec '05  
GeneralRe: help please... PinmemberIanussea20:22 16 Apr '07  
QuestionHow to get Application Owner Name? Pinmemberlellasr19:29 11 Dec '05  
AnswerRe: How to get Application Owner Name? PinmemberMadhu Raykar22:02 11 Dec '05  
GeneralProblems PinmemberJimD.99994:25 8 Dec '05  
QuestionWindows version? PinmemberMister Transistor10:57 6 Dec '05  
AnswerRe: Windows version? PinmemberMadhu Raykar17:40 6 Dec '05  
GeneralRe: Windows version? PinmemberWessam Fathi22:24 6 Dec '05  
GeneralRe: Windows version? PinmemberMadhu Raykar0:13 8 Dec '05  
GeneralRe: Windows version? PinmemberVasudevan Deepak Kumar18:25 30 Jul '07  
Generalfeature requests Pinmembernnnnnnn4:29 6 Dec '05  
GeneralRe: feature requests PinmemberMadhu Raykar5:25 6 Dec '05  
GeneralCool PinmemberRazr3335:33 4 Dec '05  
GeneralRe: Cool PinmemberDandy Cheung14:33 4 Dec '05  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 4 Dec 2005
Article Copyright 2005 by Madhu Raykar
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid