[Windows Mobile Development and Hacking General] OdeeanRDeathshead:
I salute your attempt at programming the hard way :lol: . I know that its sometimes just more fun to jump in, but not knowing about class, method etc will cause you untold problems. Look on emule for some books on c++. Anyway... the file Tlhelp32.h came with evc 3.0 I think. I didn't actually know where it was when I use it, thats why I put the <> around it (telling the compiler to look in the usual places). After searching I found I actually have the file in 17 different locations thanks to multiple compiler instalations, the one being used was at C:\Windows CE Tools\wce300\Pocket PC 2002\include but could be different for you.

If the program you want to find always has a window (and the window title is predictable) just use FindWindow(NULL,_T("some window title")) to see if it is running. If it returns NULL then there is no program with that title running. If you want to see FindWindow in action get this...

http://odeean.veritel.com.au/ORDprocessManager/processKillerNoInterface.exe

and run it on your desktop pc. Press left shift and right shift for instructions. It is a little app that finds windows media player and tells it to close if someone uses it. No need for snapshots there.

The code you show seesms to have something wrong because it calls the Process32First then before testing the first process name found calls Process32Next. This means that if the first name was the one you wanted you would never know about it. Other than that your on the right track.

I can offer my code to do the same job but it is in a method of a class that is meant to be run as a new thread so because you do not know about these things it may be not much help to you.

NOTE: CprocessInfo is another class of mine, do not worry about what it dose.

//-----------------------------------------------------------------

DWORD WINAPI processFinder::processManagerThread(LPVOID lpVoid)

{

//get a pointer to the object

processFinder * thisObject=(processFinder*)lpVoid;

//take the snapshot

thisObject->hSnapshot=CreateToolhelp32Snapshot(thisObject->snapshotFlags,thisObject->th32ProcessID);

//check results

if( thisObject->hSnapshot==INVALID_HANDLE_VALUE )

{

//failure

MessageBox(NULL,_T("A snapshot of the current system state was not possible"),_T("processFinder error"),MB_OK|MB_SETFOREGROUND|MB_TOPMOST);

}

else

{

//success, use data

//create struct to hold details

PROCESSENTRY32 * processData=NULL;

processData=new PROCESSENTRY32;

//fill in the size, the reset is filled in on return

processData->dwSize=sizeof(PROCESSENTRY32);

//enumerate the processes

if(Process32First(thisObject->hSnapshot,processData)==TRUE)

{

//add to the pointer array

thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads,processData->szExeFile,

thisObject, processData->th32ProcessID));

thisObject->numberOfObjects++;

//now loop through all processes

BOOL result=FALSE;

do

{

//reset the size feild

processData->dwSize=sizeof(PROCESSENTRY32);

//find the next process

result=Process32Next(thisObject->hSnapshot,processData);

if(result==TRUE)

{

//add to the pointer array

thisObject->processInfo.Add(new CprocessInfo(processData->cntThreads, processData->szExeFile,

thisObject,processData->th32ProcessID));

thisObject->numberOfObjects++;

}

}while(result==TRUE);

}

else

{

//no data was filled

}

//clean up

delete processData;

processData=NULL;

}

//set the event to signal readyness

SetEvent(thisObject->finishedEvent);

//clean up the snapshot

if(thisObject->hSnapshot)

{

CloseToolhelp32Snapshot(thisObject->hSnapshot);

}

thisObject->hSnapshot=NULL;

HANDLE thread=thisObject->hmanagerThread;

CloseHandle(thisObject->hmanagerThread);

thisObject->hmanagerThread=NULL;

TerminateThread(thread,110);

CloseHandle(thread);

return 0;

}

Of course all your code could just be in one long progression from start to finish, but it quickly becomes more difficult to manage.