ok great, I quite got it
Another problem now :
Code:
#include <windows.h>
#include <stdio.h>
#include "psapi.h"
void LookforMyProcessAndPID( DWORD processID )
{
char szProcessName[MAX_PATH] = "<unknown>";
char processtofind[MAX_PATH] = "svchost.exe";
// 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) );
}
}
// Print the process name and identifier.
if (szProcessName == processtofind)
{
printf( "%s (PID: %u)\n", szProcessName, processID );
}
CloseHandle( hProcess );
}
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++ )
LookforMyProcessAndPID( aProcesses[i] );
system("PAUSE");
}
this code works if I cancel the
Code:
if (szProcessName == processtofind)
if I cancel it, I have the list of all process and PID... but I want to add this control...too bad it seems to fail...
It looks for szProcessName and looks if it is equal to processtofind
Code:
char processtofind[MAX_PATH] = "svchost.exe";
any suggestion ? I can't figure out why it doesn't work... szProcessName is a char[] and processtofind too.. and szProcessName it is,at least one time in the for cicle in the main, svchost.exe...