In the program I want to write, I need a reliable method in which to check to see if a particular program is running. I thought about looping through the windows processes and getting the window title of each process ID. However I think even with that method I am still prone to not finding the program. What do you guys think? Is there a reliable method to finding a running instance of a program? The program has it's own API. I suppose I could try and get a reference to the programs object model in some way, but if that fails, what other methods could I use?
You can check if a certain named binary is loaded in memory using "CreateToolhelp32Snapshot", "Process32First" and "Process32Next" and checking the szExeFile property for the 'PROCESSENTRY32' struct that the last two fill out:
Hey this looks great, thank you for the links as well. Found some useful code to test. What if however, there was more than one instance open? If there were 2 or 3 instances of a program open, how would you tell them apart? Could you do that using this method?
However so far, the code isn't working as I hoped. It does not return all of the running processes on my machine. It only returns a few of them. I thought perhaps that the problem might be because I am compiling the code as a 32 bit console application. So I tried changing the Solution Platform in Visual Studio 2015 to x64. However that didn't improve the results. It yielded less processes. I find if Solution Platform is on x86, it actually yields more processes. I read online that in order to find x64 bit processes you have to run the code from a x64 bit process.
Anyway, I'm not sure what I am doing wrong. Any help would be appreciated. I have spent a long time trying to get this code to give me all of the processes. It would be nice to finally be done with it.
Have to tried using a program like WinSpy++ or sth. similar to see if maybe this particular program has a unique class or window name you can search for?
"Note that you can use the QueryFullProcessImageName function to retrieve the full name of an executable image for both 32- and 64-bit processes from a 32-bit process."