+ Reply to Thread
Results 1 to 2 of 2

Thread: Enumerate all the running processes using WIN32 APIs

  1. #1

    Enumerate all the running processes using WIN32 APIs

    Enumerate all the running processes using WIN32 APIs

  2. #2
    You can use WIN32 PSAPI APIs for this purpose.

    You will need to add #include <Psapi.h> and Psapi.lib library file

    Example:

    Code:
    #include <Psapi.h>
    
    void ListProcesses()
    {
    	DWORD dwProcesses[1024], cbNeeded, nProcesses ;
            unsigned int i ;
    
        if ( !EnumProcesses( dwProcesses, sizeof(dwProcesses), &cbNeeded ) )
            return ;
    
    	nProcesses = cbNeeded / sizeof(DWORD) ;
    
    	int nFilesRunning = 1 ;
    	for(i = 0; i < nProcesses; i++ )
    	{
    		HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
    									   FALSE, dwProcesses[i] ) ;
    
    		// Get the process name.
    
    		if (NULL == hProcess )
    		{
    			continue ;
    		}
    		HMODULE hMod ;
    		DWORD cbNeeded ;
    
    		if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), 
    			 &cbNeeded) )
    		{
    			char szProcessName[MAX_PATH] = { 0 } ;
    			GetModuleBaseName( hProcess, hMod, szProcessName, 
    							   sizeof(szProcessName) ) ;
    
    			OutputDebugString(szProcessName) ;
    			OutputDebugString("\r\n") ;
    		}
    
    		CloseHandle( hProcess ) ;
    	}
    }
    
    void UseListProcesses()
    {
            CheckForProcesses() ;
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts