View Single Post
Old Feb 23rd, 2006, 9:55 AM   #6
badbasser98
Hobbyist Programmer
 
Join Date: Mar 2005
Location: United States
Posts: 124
Rep Power: 4 badbasser98 is on a distinguished road
This is the sample code off of MSDN for Enumerating all processes... Would someone mind explaining where in the code the ProcessID is being obtained, or does it show this?

 #include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "psapi.h"
 
void PrintProcessNameAndID( DWORD processID )
{
	TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>");
 
	// Get a handle to the process.
 
	HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
								 PROCESS_VM_READ,
								 FALSE, processID );
 
	// Get the process name.
 
	if (NULL != hProcess )
	{
		HMODULE hMod;
		DWORD cbNeeded;
 
		if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod), 
			 &cbNeeded) )
		{
			GetModuleBaseName( hProcess, hMod, szProcessName, 
							 sizeof(szProcessName)/sizeof(TCHAR) );
		}
	}
 
	// Print the process name and identifier.
 
	_tprintf( TEXT("%s (PID: %u)\n"), szProcessName, processID );
 
	CloseHandle( hProcess );
}
 
void main( )
{
	// Get the list of process identifiers.
 
	DWORD aProcesses[1024], cbNeeded, cProcesses;
	unsigned int i;
 
	if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) )
		return;
 
	// Calculate how many process identifiers were returned.
 
	cProcesses = cbNeeded / sizeof(DWORD);
 
	// Print the name and process identifier for each process.
 
	for ( i = 0; i < cProcesses; i++ )
		PrintProcessNameAndID( aProcesses[i] );
}

Thanks for the info
__________________
Learning to use C++ and loving every minute of it.
badbasser98 is offline   Reply With Quote