views:

58

answers:

2

I am going to open game process from my trainer app and write some values to memory. I have no problems with opening a process and writing a value to memory. But I can't realize how to monitor the game process availability. For example I opened a running process, user closed it and opened again. How can I track this in my code? OpenProcess handle is valid even after the process is closed (until CloseHandle called). Thank you.

+1  A: 

You can use the GetExitCodeProcess function to see if the handle you have points to a running process.

DWORD exitCode=0;
::GetExitCodeProcess(hProcess, &exitCode);
if (exitCode==STILL_ACTIVE)
  ; //process is alive

MSDN link

ngoozeff
A: 

Or else, if it's more suitable for your application to have the process termination event signalled to you (process is a waitable object):

::WaitForSingleObject(hProcess, dwTimeout);
Nikola Gedelovski