[这个贴子最后由x86在 2006/02/20 09:54pm 第 1 次编辑]
#include
#include
#pragma comment(lib,"psapi.lib")
#include "psapi.h"
void PrintProcessNameAndID( DWORD processID )
{
char szModuleName[MAX_PATH] = "undown";
char FilePath[MAX_PATH] = "unknown";
// Get a handle to the process.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, processID );
// Get the process path.
HMODULE hMod[500];
DWORD cbNeeded;
DWORD ModNum;
if (NULL != hProcess )
{
if ( EnumProcessModules( hProcess, hMod, sizeof(hMod),
&cbNeeded) )
{GetModuleFileNameEx(hProcess,hMod[0],FilePath,MAX_PATH);
printf( "\n\n%s\n(Process ID: %u)\nnumber of modules:%d\n", FilePath, processID, cbNeeded/sizeof(HMODULE), FilePath );
for(ModNum = 0 ; ModNum < cbNeeded/sizeof(HMODULE); ModNum++)
{
GetModuleBaseName( hProcess, hMod[ModNum], szModuleName,
sizeof(szModuleName) );
printf("\nModules name : %s",szModuleName);
}
}
else return;
}
else return;
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 );
}
:em10: :em10: :em10: |